- 
                Notifications
    
You must be signed in to change notification settings  - Fork 5.5k
 
New Components - motive #15246
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
          
     Merged
      
      
    
  
     Merged
                    New Components - motive #15246
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            8 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      6494014
              
                motive init
              
              
                luancazarine b57dba8
              
                [Components] motive #15221
              
              
                luancazarine 00eb589
              
                pnpm update
              
              
                luancazarine edc5acd
              
                Sources
              
              
                luancazarine 2e6247c
              
                pnpm update
              
              
                luancazarine 903d378
              
                Merge branch 'master' into issue-15221
              
              
                luancazarine 328e964
              
                pnpm update
              
              
                luancazarine 63452b4
              
                fix filename
              
              
                luancazarine File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
        
          
          
            75 changes: 75 additions & 0 deletions
          
          75 
        
  components/motive/actions/find-user-details/find-user-details.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { ConfigurationError } from "@pipedream/platform"; | ||
| import { clearObj } from "../../common/util.mjs"; | ||
| import motive from "../../motive.app.mjs"; | ||
| 
     | 
||
| export default { | ||
| key: "motive-find-user-details", | ||
| name: "Find User Details", | ||
| description: "Retrieve user details based on specific criteria. [See the documentation](https://developer.gomotive.com/reference/users-lookup)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| motive, | ||
| alert: { | ||
| 
         Check warning on line 13 in components/motive/actions/find-user-details/find-user-details.mjs 
    
   | 
||
| type: "alert", | ||
| alertType: "info", | ||
| content: "If you provide more than one prop, only one will be considered, the others will be ignored.", | ||
| }, | ||
                
      
                  luancazarine marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| username: { | ||
| type: "string", | ||
| label: "Username", | ||
| description: "Username to retrieve user details", | ||
| optional: true, | ||
| }, | ||
| email: { | ||
| type: "string", | ||
| label: "Email", | ||
| description: "Email to retrieve user details", | ||
| optional: true, | ||
| }, | ||
| driverCompanyId: { | ||
| propDefinition: [ | ||
| motive, | ||
| "driverCompanyId", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| let response; | ||
| const criteria = []; | ||
| 
     | 
||
| const { | ||
| username, email, driverCompanyId, | ||
| } = this; | ||
| if (!username && !email && !driverCompanyId) { | ||
| throw new Error("At least one of 'Username', 'Email', 'Driver Company Id' must be provided."); | ||
| } | ||
| 
     | 
||
| if (username) criteria.push(`username: ${username}`); | ||
| if (email) criteria.push(`email: ${email}`); | ||
| if (driverCompanyId) criteria.push(`driverCompanyId: ${driverCompanyId}`); | ||
| 
     | 
||
| try { | ||
| response = await this.motive.retrieveUserDetails({ | ||
| $, | ||
| params: clearObj({ | ||
| username, | ||
| email, | ||
| driver_company_id: driverCompanyId, | ||
| }), | ||
| }); | ||
| 
     | 
||
| } catch ({ response: { data } }) { | ||
| if (data.error_message === "user not found") { | ||
| response = { | ||
| user: null, | ||
| }; | ||
| } else { | ||
| throw new ConfigurationError(data.error_message); | ||
| } | ||
| } | ||
                
      
                  luancazarine marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| $.export("$summary", `Successfully retrieved user details for ${criteria.join(", ")}`); | ||
| return response; | ||
| }, | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| export const clearObj = (obj) => { | ||
| return Object.entries(obj) | ||
| .filter(([ | ||
| _, | ||
| v, | ||
| ]) => (v != null && v != "" && _ != "$emit")) | ||
| .reduce((acc, [ | ||
| k, | ||
| v, | ||
| ]) => ({ | ||
| ...acc, | ||
| [k]: (!Array.isArray(v) && v === Object(v)) | ||
| ? clearObj(v) | ||
| : v, | ||
| }), {}); | ||
| }; | ||
                
      
                  luancazarine marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,11 +1,124 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
| 
     | 
||
| export default { | ||
| type: "app", | ||
| app: "motive", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| driverId: { | ||
| type: "string", | ||
| label: "Driver ID", | ||
| description: "Filter to a specific driver", | ||
| }, | ||
| safetyCategory: { | ||
| type: "string", | ||
| label: "Safety Category", | ||
| description: "Filter to a specific safety category", | ||
| }, | ||
| driverCompanyId: { | ||
| type: "string", | ||
| label: "Driver Company ID", | ||
| description: "Driver company ID to retrieve user details", | ||
| async options({ page }) { | ||
| const { users } = await this.listUsers({ | ||
| params: { | ||
| page_no: page + 1, | ||
| role: "driver", | ||
| }, | ||
| }); | ||
| 
     | 
||
| return users.map(({ user }) => ({ | ||
| label: user.email || `${user.first_name} ${user.last_name}`, | ||
| value: user.driver_company_id, | ||
| })); | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return "https://api.gomotive.com/v1"; | ||
| }, | ||
| _headers() { | ||
| return { | ||
| Authorization: `Bearer ${this.$auth.oauth_access_token}`, | ||
| }; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, path, ...opts | ||
| }) { | ||
| return axios($, { | ||
| url: this._baseUrl() + path, | ||
| headers: this._headers(), | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listHosViolations(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "GET", | ||
| path: "/hos_violations", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listUsers(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/users", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| createWebhook(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/company_webhooks", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| updateWebhook({ | ||
| webhookId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| method: "PUT", | ||
| path: `/company_webhooks/${webhookId}`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listDriverPerformanceEvents(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "GET", | ||
| path: "/driver_performance_events", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| retrieveUserDetails(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "GET", | ||
| path: "/users/lookup", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| async *paginate({ | ||
| fn, params = {}, fieldName, maxResults = null, ...opts | ||
| }) { | ||
| let hasMore = false; | ||
| let count = 0; | ||
| let page = 0; | ||
| 
     | 
||
| do { | ||
| params.page = ++page; | ||
| const data = await fn({ | ||
| params, | ||
| ...opts, | ||
| }); | ||
| const items = data[fieldName]; | ||
| for (const d of items) { | ||
| yield d; | ||
| 
     | 
||
| if (maxResults && ++count === maxResults) { | ||
| return count; | ||
| } | ||
| } | ||
| 
     | 
||
| hasMore = items.length; | ||
| 
     | 
||
| } while (hasMore); | ||
| }, | ||
                
      
                  luancazarine marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| }, | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@pipedream/motive", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream Motive Components", | ||
| "main": "motive.app.mjs", | ||
| "keywords": [ | ||
| 
        
          
        
         | 
    @@ -11,5 +11,9 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.0.3", | ||
| "uuid": "^11.0.4" | ||
| } | ||
| } | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; | ||
| import motive from "../../motive.app.mjs"; | ||
| 
     | 
||
| export default { | ||
| props: { | ||
| motive, | ||
| db: "$.service.db", | ||
| timer: { | ||
| type: "$.interface.timer", | ||
| default: { | ||
| intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| _getLastId() { | ||
| return this.db.get("lastId") || 0; | ||
| }, | ||
| _setLastId(lastId) { | ||
| this.db.set("lastId", lastId); | ||
| }, | ||
| async emitEvent(maxResults = false) { | ||
| const lastId = this._getLastId(); | ||
| const fieldName = this.getFieldName(); | ||
| 
     | 
||
| const response = this.motive.paginate({ | ||
| fn: this.getFunction(), | ||
| fieldName: `${fieldName}s`, | ||
| }); | ||
| 
     | 
||
| let responseArray = []; | ||
| for await (const item of response) { | ||
| const data = item[fieldName]; | ||
| if (data.id <= lastId) break; | ||
| responseArray.push(data); | ||
| } | ||
| 
     | 
||
| if (responseArray.length) { | ||
| if (maxResults && (responseArray.length > maxResults)) { | ||
| responseArray.length = maxResults; | ||
| } | ||
| this._setLastId(responseArray[0].id); | ||
| } | ||
| 
     | 
||
| for (const item of responseArray.reverse()) { | ||
| const data = item[fieldName]; | ||
| this.$emit(data, { | ||
| id: data.id, | ||
| summary: this.getSummary(data), | ||
| ts: Date.parse(data.start_time || new Date()), | ||
| }); | ||
| } | ||
| }, | ||
| }, | ||
| hooks: { | ||
| async deploy() { | ||
| await this.emitEvent(25); | ||
| }, | ||
| }, | ||
| async run() { | ||
| await this.emitEvent(); | ||
| }, | ||
| }; | 
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.