- 
                Notifications
    
You must be signed in to change notification settings  - Fork 5.5k
 
New Components - ortto #14703
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 - ortto #14703
Changes from 3 commits
      Commits
    
    
            Show all changes
          
          
            10 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      afad520
              
                ortto init
              
              
                luancazarine fdf97fa
              
                [Components] ortto #13209
              
              
                luancazarine 2076942
              
                pnpm update
              
              
                luancazarine 9d870d4
              
                fix dependency import
              
              
                luancazarine 1e7849c
              
                Merge branch 'master' into issue-13209
              
              
                luancazarine e08200c
              
                Merge branch 'master' into issue-13209
              
              
                luancazarine aa0d91a
              
                pnpm update
              
              
                luancazarine f7eb161
              
                some adjusts
              
              
                luancazarine f752aff
              
                Improve props description
              
              
                vunguyenhung fbb4bbd
              
                Improve prop description
              
              
                vunguyenhung 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 | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const LIMIT = 100; | 
This file was deleted.
      
      Oops, something went wrong.
      
    
  
        
          
          
            51 changes: 51 additions & 0 deletions
          
          51 
        
  components/ortto/actions/create-custom-activity/create-custom-activity.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,51 @@ | ||
| import { parseObject } from "../../common/utils.mjs"; | ||
| import ortto from "../../ortto.app.mjs"; | ||
| 
     | 
||
| export default { | ||
| key: "ortto-create-custom-activity", | ||
| name: "Create Custom Activity", | ||
| description: "Creates a unique activity for a person. Can optionally initialize a new record beforehand. [See the documentation](https://help.ortto.com/developer/latest/api-reference/activity/index.html)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| ortto, | ||
| activityId: { | ||
| propDefinition: [ | ||
| ortto, | ||
| "activityId", | ||
| ], | ||
| }, | ||
| attributes: { | ||
| propDefinition: [ | ||
| ortto, | ||
| "attributes", | ||
| ], | ||
| }, | ||
| fields: { | ||
| propDefinition: [ | ||
| ortto, | ||
| "fields", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.ortto.createCustomActivity({ | ||
| $, | ||
| data: { | ||
| "activities": [ | ||
| { | ||
| activity_id: this.activityId, | ||
| attributes: parseObject(this.attributes), | ||
| fields: parseObject(this.fields), | ||
| }, | ||
| ], | ||
| "merge_by": [ | ||
| "str::email", | ||
| ], | ||
| }, | ||
| }); | ||
| 
     | 
||
| $.export("$summary", "Successfully created activity"); | ||
| return response; | ||
| }, | ||
| }; | ||
        
          
          
            109 changes: 109 additions & 0 deletions
          
          109 
        
  components/ortto/actions/create-person/create-person.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,109 @@ | ||
| import { clearObj } from "../../common/utils.mjs"; | ||
| import ortto from "../../ortto.app.mjs"; | ||
| 
     | 
||
| export default { | ||
| key: "ortto-create-person", | ||
| name: "Create or Update a Person", | ||
| description: "Create or update a preexisting person in the Ortto account. [See the documentation](https://help.ortto.com/a-250-api-reference)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| ortto, | ||
| firstName: { | ||
| type: "string", | ||
| label: "First Name", | ||
| description: "The person's first name.", | ||
| optional: true, | ||
| }, | ||
| lastName: { | ||
| type: "string", | ||
| label: "Last Name", | ||
| description: "The person's last name.", | ||
| optional: true, | ||
| }, | ||
| phone: { | ||
| type: "string", | ||
| label: "Phone", | ||
| description: "The person's phone number.", | ||
| }, | ||
                
      
                  luancazarine marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| email: { | ||
| type: "string", | ||
| label: "Email", | ||
| description: "The person's email address.", | ||
| }, | ||
| city: { | ||
| type: "string", | ||
| label: "City", | ||
| description: "The person's address city.", | ||
| optional: true, | ||
| }, | ||
| country: { | ||
| type: "string", | ||
| label: "Country", | ||
| description: "The person's address country.", | ||
| optional: true, | ||
| }, | ||
| region: { | ||
| type: "string", | ||
| label: "Region", | ||
| description: "The person's address region.", | ||
| optional: true, | ||
| }, | ||
| birthday: { | ||
| type: "string", | ||
| label: "Birthday", | ||
| description: "The person's birth date.", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| ortto, | ||
| ...props | ||
| } = this; | ||
| 
     | 
||
| const birthday = {}; | ||
| if (props.birthday) { | ||
| const date = new Date(props.birthday); | ||
| birthday.day = date.getDate(); | ||
| birthday.month = date.getMonth() + 1; | ||
| birthday.year = date.getFullYear(); | ||
| } | ||
                
      
                  luancazarine marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| const response = await ortto.createPerson({ | ||
| data: { | ||
| people: [ | ||
| { | ||
| fields: clearObj({ | ||
| "str::first": props.firstName, | ||
| "str::last": props.lastName, | ||
| "phn::phone": { | ||
| "phone": props.phone, | ||
| "parse_with_country_code": true, | ||
| }, | ||
| "str::email": props.email, | ||
| "geo::city": { | ||
| name: props.city, | ||
| }, | ||
| "geo::country": { | ||
| name: props.country, | ||
| }, | ||
| "geo::region": { | ||
| name: props.region, | ||
| }, | ||
| "dtz::b": birthday, | ||
| }), | ||
| }, | ||
| ], | ||
| async: false, | ||
| merge_by: [ | ||
| "str::email", | ||
| ], | ||
| merge_strategy: 3, | ||
| find_strategy: 0, | ||
| }, | ||
| }); | ||
| $.export("$summary", "Person successfully initialized or updated!"); | ||
| 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,39 @@ | ||
| import ortto from "../../ortto.app.mjs"; | ||
| 
     | 
||
| export default { | ||
| key: "ortto-opt-out-sms", | ||
| name: "Opt Out of SMS", | ||
| description: "Allows a user to opt-out from all SMS communications. [See the documentation](https://help.ortto.com/a-250-api-reference)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| ortto, | ||
| userEmail: { | ||
| propDefinition: [ | ||
| ortto, | ||
| "userEmail", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.ortto.updatePerson({ | ||
| data: { | ||
| people: [ | ||
| { | ||
| fields: { | ||
| "str::email": this.userEmail, | ||
| "bol::sp": false, | ||
| }, | ||
| }, | ||
| ], | ||
| async: false, | ||
| merge_by: [ | ||
| "str::email", | ||
| ], | ||
| }, | ||
| }); | ||
                
      
                  luancazarine marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| $.export("$summary", `Successfully opted out SMS for User ID: ${this.userEmail}`); | ||
| return response; | ||
| }, | ||
| }; | ||
This file was deleted.
      
      Oops, something went wrong.
      
    
  
  
    
      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,41 @@ | ||
| export const clearObj = (obj) => { | ||
| return Object.entries(obj) | ||
| .filter(([ | ||
| , | ||
| v, | ||
| ]) => (v != null && v != "" && JSON.stringify(v) != "{}")) | ||
| .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
         | 
||
| 
     | 
||
| export const parseObject = (obj) => { | ||
| if (!obj) return undefined; | ||
| 
     | 
||
| if (Array.isArray(obj)) { | ||
| return obj.map((item) => { | ||
| if (typeof item === "string") { | ||
| try { | ||
| return JSON.parse(item); | ||
| } catch (e) { | ||
| return item; | ||
| } | ||
| } | ||
| return item; | ||
| }); | ||
| } | ||
| if (typeof obj === "string") { | ||
| try { | ||
| return JSON.parse(obj); | ||
| } catch (e) { | ||
| return obj; | ||
| } | ||
| } | ||
| return obj; | ||
| }; | ||
  
    
      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,115 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
| import { LIMIT } from "../../common/constants.mjs"; | ||
| 
     | 
||
| export default { | ||
| type: "app", | ||
| app: "ortto", | ||
| propDefinitions: { | ||
| userEmail: { | ||
| type: "string", | ||
| label: "User Email", | ||
| description: "Specify the user email to opt out from all SMS communications.", | ||
| async options({ page }) { | ||
| const { contacts } = await this.listPeople({ | ||
| data: { | ||
| limit: LIMIT, | ||
| offset: LIMIT * page, | ||
| fields: [ | ||
| "str::first", | ||
| "str::last", | ||
| "str::email", | ||
| ], | ||
| }, | ||
| }); | ||
| 
     | 
||
| return contacts.map(({ fields }) => ({ | ||
| label: `${fields["str::first"]} ${fields["str::last"]} (${fields["str::email"]})`, | ||
| value: fields["str::email"], | ||
| })); | ||
| }, | ||
| }, | ||
| activityId: { | ||
| type: "string", | ||
| label: "Activity Id", | ||
| description: "The Id of the activity definition. You can find the id by clicking on the activity, the id will be in the url \"/activities/{ACTIVITY_ID}/overview\"", | ||
| }, | ||
| fields: { | ||
| type: "object", | ||
| label: "Fields", | ||
| description: "An object with the fields of the activity. You can find the fields by clicking on the activity and on the Developer button.", | ||
| }, | ||
| attributes: { | ||
| type: "object", | ||
| label: "Attributes", | ||
| description: "An object with the attributes. You can find the attributes by clicking on the activity and on the Developer button.", | ||
| }, | ||
| }, | ||
| methods: { | ||
| _baseUrl() { | ||
| return `https://${this.$auth.region}/v1`; | ||
| }, | ||
| _headers() { | ||
| return { | ||
| "X-Api-Key": `${this.$auth.api_key}`, | ||
| "Content-Type": "application/json", | ||
| }; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, path, ...opts | ||
| }) { | ||
| return axios($, { | ||
| method: "POST", | ||
| url: this._baseUrl() + path, | ||
| headers: this._headers(), | ||
| ...opts, | ||
| }); | ||
| }, | ||
                
      
                  luancazarine marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| listPeople(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/person/get", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| updatePerson(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/person/merge", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| createPerson(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/person/merge", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| createCustomActivity(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/activities/create", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| async *paginate({ | ||
| fn, data = {}, fieldName, ...opts | ||
| }) { | ||
| let hasMore = false; | ||
| let page = 0; | ||
| 
     | 
||
| do { | ||
| data.limit = LIMIT; | ||
| data.offset = LIMIT * page++; | ||
| const response = await fn({ | ||
| data, | ||
| ...opts, | ||
| }); | ||
| for (const d of response[fieldName]) { | ||
| yield d; | ||
| } | ||
| 
     | 
||
| hasMore = response.has_more; | ||
| 
     | 
||
| } while (hasMore); | ||
| }, | ||
| }, | ||
| }; | ||
      
      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.