- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.5k
New Components - refiner #15497
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 - refiner #15497
Changes from 3 commits
      Commits
    
    
            Show all changes
          
          
            7 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      9779bfb
              
                refiner init
              
              
                luancazarine 720ad67
              
                [Components] tinyurl #15135
              
              
                luancazarine b228acd
              
                pnpm update
              
              
                luancazarine f5d2b27
              
                Update components/refiner/sources/new-segment-entry/new-segment-entry…
              
              
                luancazarine 8f0c540
              
                some adjusts
              
              
                luancazarine 62a1b74
              
                fix import
              
              
                luancazarine 07b649b
              
                some adjusts
              
              
                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
        
          
          
            43 changes: 43 additions & 0 deletions
          
          43 
        
  components/refiner/actions/identify-user/identify-user.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,43 @@ | ||
| import { ConfigurationError } from "@pipedream/platform"; | ||
| import refiner from "../../refiner.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "refiner-identify-user", | ||
| name: "Identify User", | ||
| description: "Creates or updates a user profile in Refiner. [See the documentation](https://refiner.io/docs/api/#identify-user)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| refiner, | ||
| userId: { | ||
| propDefinition: [ | ||
| refiner, | ||
| "userId", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| email: { | ||
| propDefinition: [ | ||
| refiner, | ||
| "email", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| if (!this.userId && !this.email) { | ||
| throw new ConfigurationError("Either User Id or E mail must be provided to identify the user."); | ||
|         
                  luancazarine marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| } | ||
|  | ||
| const response = await this.refiner.identifyUser({ | ||
| $, | ||
| data: { | ||
| id: this.userId, | ||
| email: this.email, | ||
| }, | ||
| }); | ||
|         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
|  | ||
| $.export("$summary", `User identified successfully. Contact UUID: ${response.contact_uuid}`); | ||
| 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,48 @@ | ||
| import refiner from "../../refiner.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "refiner-track-event", | ||
| name: "Track Event", | ||
| description: "Tracks a user event in Refiner. [See the documentation](https://refiner.io/docs/api/#track-event)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| refiner, | ||
| eventName: { | ||
| type: "string", | ||
| label: "Event Name", | ||
| description: "The name of the event or signal being tracked.", | ||
| }, | ||
|         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| userId: { | ||
| propDefinition: [ | ||
| refiner, | ||
| "userId", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| email: { | ||
| propDefinition: [ | ||
| refiner, | ||
| "email", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| if (!this.userId && !this.email) { | ||
| throw new Error("Either userId or email must be provided to track the event."); | ||
|         
                  luancazarine marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| } | ||
|         
                  luancazarine marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
|  | ||
| const response = await this.refiner.trackEvent({ | ||
| $, | ||
| data: { | ||
| event: this.eventName, | ||
| id: this.userId, | ||
| email: this.email, | ||
| }, | ||
| }); | ||
|         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
|  | ||
| $.export("$summary", `Tracked event "${this.eventName}" successfully.`); | ||
| 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 | 
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@pipedream/refiner", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream Refiner Components", | ||
| "main": "refiner.app.mjs", | ||
| "keywords": [ | ||
|  | @@ -11,5 +11,8 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.0.3" | ||
| } | ||
| } | ||
| } | ||
  
    
      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,133 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
|  | ||
| export default { | ||
| type: "app", | ||
| app: "refiner", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| userId: { | ||
| type: "string", | ||
| label: "User ID", | ||
| description: "The ID of the user to identify or track events for.", | ||
| async options({ page }) { | ||
| const { items } = await this.listContacts({ | ||
| params: { | ||
| page: page + 1, | ||
| }, | ||
| }); | ||
|  | ||
| return items.map(({ | ||
| uuid: value, email: label, | ||
| }) => ({ | ||
| label, | ||
| value, | ||
| })); | ||
| }, | ||
| }, | ||
| email: { | ||
| type: "string", | ||
| label: "Email", | ||
| description: "The email address of the user to identify or track events for.", | ||
| optional: true, | ||
| }, | ||
| segmentId: { | ||
| type: "string", | ||
| label: "Segment ID", | ||
| description: "The ID of the segment to emit events for.", | ||
| async options({ page }) { | ||
| const { items } = await this.listSegments({ | ||
| params: { | ||
| page: page + 1, | ||
| }, | ||
| }); | ||
|  | ||
| return items.map(({ | ||
| uuid: value, name: label, | ||
| }) => ({ | ||
| label, | ||
| value, | ||
| })); | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return "https://api.refiner.io/v1"; | ||
| }, | ||
| _headers() { | ||
| return { | ||
| "Authorization": `Bearer ${this.$auth.api_key}`, | ||
| }; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, path, ...opts | ||
| }) { | ||
| return axios($, { | ||
| url: this._baseUrl() + path, | ||
| headers: this._headers(), | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listContacts(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/contacts", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listResponses(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/responses", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listSegments(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/segments", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| identifyUser(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/identify-user", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| trackEvent(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/track-event", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| async *paginate({ | ||
| fn, params = {}, maxResults = null, ...opts | ||
| }) { | ||
| let hasMore = false; | ||
| let count = 0; | ||
| let page = 0; | ||
|  | ||
| do { | ||
| params.page = ++page; | ||
| const { | ||
| items, | ||
| pagination: { | ||
| current_page, last_page, | ||
| }, | ||
| } = await fn({ | ||
| params, | ||
| ...opts, | ||
| }); | ||
| for (const d of items) { | ||
| yield d; | ||
|  | ||
| if (maxResults && ++count === maxResults) { | ||
| return count; | ||
| } | ||
| } | ||
|  | ||
| hasMore = current_page < last_page; | ||
|  | ||
| } while (hasMore); | ||
| }, | ||
| }, | ||
| }; | 
  
    
      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,66 @@ | ||
| import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; | ||
| import refiner from "../../refiner.app.mjs"; | ||
|  | ||
| export default { | ||
| props: { | ||
| refiner, | ||
| db: "$.service.db", | ||
| timer: { | ||
| type: "$.interface.timer", | ||
| default: { | ||
| intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| _getLastDate() { | ||
| return this.db.get("lastDate") || 0; | ||
| }, | ||
| _setLastDate(lastDate) { | ||
| this.db.set("lastDate", lastDate); | ||
| }, | ||
| async emitEvent(maxResults = false) { | ||
| const lastDate = this._getLastDate(); | ||
|  | ||
| const response = this.refiner.paginate({ | ||
| fn: this.getFunction(), | ||
| params: this.getParams(), | ||
| }); | ||
|         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
|  | ||
| let responseArray = []; | ||
| for await (const item of response) { | ||
| const itemDate = this.getItemDate(item); | ||
|  | ||
| if (!itemDate.length) continue; | ||
|         
                  luancazarine marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| if (Date.parse(itemDate) <= lastDate) break; | ||
|         
                  luancazarine marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| responseArray.push(item); | ||
| } | ||
|  | ||
| if (responseArray.length) { | ||
| if (maxResults && (responseArray.length > maxResults)) { | ||
| responseArray.length = maxResults; | ||
| } | ||
| const itemDate = this.getItemDate(responseArray[0]); | ||
| this._setLastDate(itemDate); | ||
| } | ||
|         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
|  | ||
| for (const item of responseArray.reverse()) { | ||
| const itemDate = this.getItemDate(item); | ||
|  | ||
| this.$emit(item, { | ||
| id: item.uuid, | ||
| summary: this.getSummary(item), | ||
| ts: Date.parse(itemDate), | ||
| }); | ||
| } | ||
| }, | ||
| }, | ||
| hooks: { | ||
| async deploy() { | ||
| await this.emitEvent(25); | ||
| }, | ||
| }, | ||
| async run() { | ||
| await this.emitEvent(); | ||
| }, | ||
| }; | ||
        
          
          
            40 changes: 40 additions & 0 deletions
          
          40 
        
  components/refiner/sources/new-segment-entry/new-segment-entry.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,40 @@ | ||
| import common from "../common/base.mjs"; | ||
| import sampleEmit from "./test-event.mjs"; | ||
|  | ||
| export default { | ||
| ...common, | ||
| key: "refiner-new-segment-entry", | ||
| name: "New Segment Entry", | ||
| description: "Emit new event whenever a user enters a segment in Refiner.", | ||
|         
                  luancazarine marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| props: { | ||
| ...common.props, | ||
| segmentId: { | ||
| propDefinition: [ | ||
| common.props.refiner, | ||
| "segmentId", | ||
| ], | ||
| }, | ||
| }, | ||
| methods: { | ||
| ...common.methods, | ||
| getFunction() { | ||
| return this.refiner.listContacts; | ||
| }, | ||
| getParams() { | ||
| return { | ||
| regment_uuid: this.segmentId, | ||
|         
                  luancazarine marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| }; | ||
|         
                  luancazarine marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| }, | ||
| getSummary(item) { | ||
| return `User ${item.email} entered segment ${this.segmentId}`; | ||
| }, | ||
|         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| getItemDate(item) { | ||
| return item.segments | ||
| .filter(({ uuid }) => uuid === this.segmentId)[0].created_at; | ||
| }, | ||
|         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| }, | ||
| sampleEmit, | ||
| }; | ||
        
          
          
            32 changes: 32 additions & 0 deletions
          
          32 
        
  components/refiner/sources/new-segment-entry/test-event.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,32 @@ | ||
| export default { | ||
| "uuid": "15cce3d0-ed5d-11ea-aaef-e58a2a43e996", | ||
| "remote_id": "Your-Contact-ID", | ||
| "email": "[email protected]", | ||
| "display_name": "Jane Doe", | ||
| "first_seen_at": "2020-09-02T20:44:24.000000Z", | ||
| "last_seen_at": "2020-09-02T21:57:50.000000Z", | ||
| "attributes": { | ||
| "a_user_attribute": "Manager", | ||
| "another_one": "Marketing", | ||
| "a_survey_answer": "9", | ||
| "another_answer": "ABC", | ||
| }, | ||
| "segments": [ | ||
| { | ||
| "uuid": "0ff87720-9ae5-11ea-bce5-65a395204572", | ||
| "name": "Power Users Segment" | ||
| }, | ||
| ], | ||
| "account": { | ||
| "uuid": "15d08cc0-ed5d-11ea-b2ce-c1b46bd4b7c4", | ||
| "remote_id": "Your-Account-Id", | ||
| "domain": "awesome.com", | ||
| "display_name": "Awesome Inc.", | ||
| "first_seen_at": "2020-09-02T20:44:24.000000Z", | ||
| "last_seen_at": "2020-09-02T21:57:50.000000Z", | ||
| "attributes": { | ||
| "an_account_attribute": "Computer Software", | ||
| "another_one": "2020", | ||
| } | ||
| } | ||
| } | 
      
      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.