- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.5k
New Components - specific #12926
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 - specific #12926
Changes from all commits
      Commits
    
    
  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
        
          
          
            167 changes: 167 additions & 0 deletions
          
          167 
        
  components/specific/actions/create-conversation/create-conversation.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,167 @@ | ||
| import specific from "../../specific.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "specific-create-conversation", | ||
| name: "Create Conversation", | ||
| description: "Create a new conversation. [See the documentation](https://public-api.specific.app/docs/mutations/createConversation)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| specific, | ||
| content: { | ||
| type: "string", | ||
| label: "Content", | ||
| description: "Conversation content as String or ProseMirror document.", | ||
| reloadProps: true, | ||
| }, | ||
| insertedAt: { | ||
| propDefinition: [ | ||
| specific, | ||
| "insertedAt", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| assignee: { | ||
| type: "string", | ||
| label: "Assignee", | ||
| description: "The user's email.", | ||
| optional: true, | ||
| }, | ||
| sourceId: { | ||
| propDefinition: [ | ||
| specific, | ||
| "sourceId", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| companyId: { | ||
| propDefinition: [ | ||
| specific, | ||
| "companyId", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| contactId: { | ||
| propDefinition: [ | ||
| specific, | ||
| "contactId", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| sourceUrl: { | ||
| type: "string", | ||
| label: "Source URL", | ||
| description: "Source url where the conversation was gathered.", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async additionalProps() { | ||
| const props = {}; | ||
| if (this.content) { | ||
| const { data: { customFields } } = await this.specific.query({ | ||
| model: "customFields", | ||
| where: "{type: {equals: conversation }}", | ||
| fields: "name", | ||
| }); | ||
| for (const { name } of customFields) { | ||
| props[`customField-${name}`] = { | ||
| type: "string", | ||
| label: name, | ||
| description: `Custom Field: ${name}`, | ||
| optional: true, | ||
| }; | ||
| } | ||
| } | ||
| return props; | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| specific, | ||
| ...data | ||
| } = this; | ||
|  | ||
| const customFields = this.specific.parseCustomFields(data); | ||
|  | ||
| const response = await specific.mutation({ | ||
| $, | ||
| model: "createConversation", | ||
| data: `{ | ||
| ${this.assignee | ||
| ? `assignee: { | ||
| connectOrIgnore: { | ||
| email: "${this.assignee}" | ||
| } | ||
| }` | ||
| : ""} | ||
| ${this.companyId | ||
| ? `company: { | ||
| connect: { | ||
| id: "${this.companyId}" | ||
| } | ||
| }` | ||
| : ""} | ||
| ${this.contactId | ||
| ? `contact: { | ||
| connect: { | ||
| id: "${this.contactId}" | ||
| } | ||
| }` | ||
| : ""} | ||
| content: "${this.content}" | ||
| ${customFields | ||
| ? `customFields: ${customFields}` | ||
| : ""} | ||
| ${this.insertedAt | ||
| ? `insertedAt: "${this.insertedAt}"` | ||
| : ""} | ||
| ${this.sourceId | ||
| ? `source: { | ||
| connect: { | ||
| id: "${this.sourceId}" | ||
| } | ||
| }` | ||
| : ""} | ||
| ${this.sourceUrl | ||
| ? `sourceUrl: "${this.sourceUrl}"` | ||
| : ""} | ||
| }`, | ||
| fields: ` | ||
| customFields | ||
| id | ||
| insertedAt | ||
| name | ||
| plainText | ||
| sourceUrl | ||
| assignee { | ||
| fullName | ||
| id | ||
| } | ||
| company { | ||
| contactsCount | ||
| customFields | ||
| id | ||
| name | ||
| visitorId | ||
| } | ||
| contact { | ||
| customFields | ||
| id | ||
| name | ||
| visitorId | ||
| } | ||
| source { | ||
| id | ||
| name | ||
| }`, | ||
| on: "Conversation", | ||
| }); | ||
|  | ||
| if (response.errors) throw new Error(response.errors[0].message); | ||
|  | ||
| $.export("$summary", `Successfully created conversation for user ID: ${response.data?.createConversation?.id}`); | ||
| 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,34 @@ | ||
| import specific from "../../specific.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "specific-find-company", | ||
| name: "Find Company", | ||
| description: "Retrieve details of a specified company. [See the documentation](https://public-api.specific.app/docs/types/Query)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| specific, | ||
| companyId: { | ||
| propDefinition: [ | ||
| specific, | ||
| "companyId", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.specific.query({ | ||
| $, | ||
| model: "companies", | ||
| where: `{id: {equals: "${this.companyId}"}}`, | ||
| fields: `id | ||
| name | ||
| customFields | ||
| visitorId | ||
| contactsCount`, | ||
| on: "Company", | ||
| }); | ||
|  | ||
| $.export("$summary", `Successfully retrieved details for company ID: ${this.companyId}`); | ||
| return response; | ||
| }, | ||
| }; | 
        
          
          
            111 changes: 111 additions & 0 deletions
          
          111 
        
  components/specific/actions/update-create-contact/update-create-contact.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,111 @@ | ||
| import specific from "../../specific.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "specific-update-create-contact", | ||
| name: "Update or Create Contact", | ||
| description: "Modify an existing contact's details or create a new one if the specified contact does not exist. [See the documentation](https://public-api.specific.app/docs/types/contact)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| specific, | ||
| contactEmail: { | ||
| propDefinition: [ | ||
| specific, | ||
| "contactEmail", | ||
| ], | ||
| reloadProps: true, | ||
| }, | ||
| companyId: { | ||
| propDefinition: [ | ||
| specific, | ||
| "companyId", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| name: { | ||
| type: "string", | ||
| label: "Name", | ||
| description: "Contact's name.", | ||
| optional: true, | ||
| }, | ||
| email: { | ||
| type: "string", | ||
| label: "New Email", | ||
| description: "New email to update", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async additionalProps() { | ||
| const props = {}; | ||
| if (this.content) { | ||
| const { data: { customFields } } = await this.specific.query({ | ||
| model: "customFields", | ||
| where: "{type: {equals: contact }}", | ||
| fields: "name", | ||
| }); | ||
| for (const { name } of customFields) { | ||
| props[`customField-${name}`] = { | ||
| type: "string", | ||
| label: name, | ||
| description: `Custom Field: ${name}`, | ||
| optional: true, | ||
| }; | ||
| } | ||
| } | ||
| return props; | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| specific, | ||
| ...data | ||
| } = this; | ||
|  | ||
| const customFields = this.specific.parseCustomFields(data); | ||
|  | ||
| const response = await specific.mutation({ | ||
| $, | ||
| model: "createOrUpdateContact", | ||
| on: "CreatedOrUpdatedContacts", | ||
| data: `{ | ||
| ${this.companyId | ||
| ? `company: { | ||
| connect: { | ||
| id: "${this.companyId}" | ||
| } | ||
| }` | ||
| : ""} | ||
| ${customFields | ||
| ? `customFields: ${customFields}` | ||
| : ""} | ||
| ${this.email | ||
| ? `email: "${this.email}"` | ||
| : ""} | ||
| ${this.name | ||
| ? `name: "${this.name}"` | ||
| : ""} | ||
| }`, | ||
| where: `{email: "${this.contactEmail}"}`, | ||
| fields: ` | ||
| contacts { | ||
| id | ||
| name | ||
| visitorId | ||
| customFields | ||
| company { | ||
| contactsCount | ||
| customFields | ||
| id | ||
| name | ||
| visitorId | ||
| } | ||
| }`, | ||
| }); | ||
|  | ||
| if (response.errors) throw new Error(response.errors[0].message); | ||
|  | ||
| $.export("$summary", `Successfully updated or created contact with email ${this.contactEmail}`); | ||
| 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,8 @@ | ||
| export const stringifyObject = (obj) => { | ||
| if (!obj) return undefined; | ||
|  | ||
| if (Array.isArray(obj)) { | ||
| return JSON.stringify(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
    
  
  
    
              
      
      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.
  
    
  
    
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.
Enhance robustness by handling other types of objects and edge cases.
The function currently only handles arrays and returns the object as is for other types. Consider enhancing it to handle other types of objects and edge cases.
export const stringifyObject = (obj) => { if (!obj) return undefined; if (Array.isArray(obj) || typeof obj === 'object') { return JSON.stringify(obj); } return String(obj); };