- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.5k
New Components - ironclad #14861
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 - ironclad #14861
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            8 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      a45459d
              
                ironclad init
              
              
                michelle0927 3a89f05
              
                wip
              
              
                michelle0927 23ba51a
              
                pnpm-lock.yaml
              
              
                michelle0927 2cd9e3e
              
                new components
              
              
                michelle0927 666f736
              
                updates
              
              
                michelle0927 f4f912d
              
                Merge remote-tracking branch 'origin/master' into issue-14837
              
              
                michelle0927 007d960
              
                pnpm-lock.yaml
              
              
                michelle0927 643edb5
              
                add invalid_param error handling
              
              
                michelle0927 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
        
          
          
            103 changes: 103 additions & 0 deletions
          
          103 
        
  components/ironclad/actions/create-record/create-record.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,103 @@ | ||
| import ironclad from "../../ironclad.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "ironclad-create-record", | ||
| name: "Create Record", | ||
| description: "Creates a new record in Ironclad. [See the documentation](https://developer.ironcladapp.com/reference/create-a-record)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| ironclad, | ||
| name: { | ||
| type: "string", | ||
| label: "Name", | ||
| description: "Name of the record", | ||
| }, | ||
| type: { | ||
| propDefinition: [ | ||
| ironclad, | ||
| "recordType", | ||
| ], | ||
| }, | ||
| links: { | ||
| propDefinition: [ | ||
| ironclad, | ||
| "recordId", | ||
| ], | ||
| type: "string[]", | ||
| label: "Links", | ||
| description: "Record ID's to link to the new record", | ||
| }, | ||
| parent: { | ||
| propDefinition: [ | ||
| ironclad, | ||
| "recordId", | ||
| ], | ||
| label: "Parent", | ||
| description: "Record ID to be set as the parent of the current record", | ||
| }, | ||
| children: { | ||
| propDefinition: [ | ||
| ironclad, | ||
| "recordId", | ||
| ], | ||
| type: "string[]", | ||
| label: "Children", | ||
| description: "Record ID's to be set as child records of the current record", | ||
| }, | ||
| properties: { | ||
| propDefinition: [ | ||
| ironclad, | ||
| "properties", | ||
| ], | ||
| reloadProps: true, | ||
| }, | ||
| }, | ||
| async additionalProps() { | ||
| const props = {}; | ||
| if (!this.properties?.length) { | ||
| return props; | ||
| } | ||
| const { properties } = await this.ironclad.getRecordsSchema(); | ||
| for (const property of this.properties) { | ||
| props[property] = { | ||
| type: properties[property].type === "boolean" | ||
| ? "boolean" | ||
| : "string", | ||
| label: properties[property].displayName, | ||
| description: properties[property].description ?? `Value of ${properties[property].displayName}`, | ||
| }; | ||
| } | ||
| return props; | ||
| }, | ||
| async run({ $ }) { | ||
| const { properties } = await this.ironclad.getRecordsSchema(); | ||
| const propertiesData = {}; | ||
| for (const property of this.properties) { | ||
| propertiesData[property] = { | ||
| type: properties[property].type, | ||
| value: this[property], | ||
| }; | ||
| } | ||
|  | ||
| const response = await this.ironclad.createRecord({ | ||
| $, | ||
| data: { | ||
| name: this.name, | ||
| type: this.type, | ||
| links: this.links?.length && this.links.map((link) => ({ | ||
| recordId: link, | ||
| })), | ||
| parent: this.parent && { | ||
| recordId: this.parent, | ||
| }, | ||
| children: this.children?.length && this.children.map((child) => ({ | ||
| recordId: child, | ||
| })), | ||
| properties: propertiesData, | ||
| }, | ||
|         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| }); | ||
| $.export("$summary", `Created record with ID: ${response.id}`); | ||
| return response; | ||
| }, | ||
| }; | ||
        
          
          
            105 changes: 105 additions & 0 deletions
          
          105 
        
  components/ironclad/actions/launch-workflow/launch-workflow.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,105 @@ | ||
| import ironclad from "../../ironclad.app.mjs"; | ||
| import { ConfigurationError } from "@pipedream/platform"; | ||
| import { | ||
| getAttributeDescription, parseValue, | ||
| } from "../../common/utils.mjs"; | ||
|  | ||
| export default { | ||
| key: "ironclad-launch-workflow", | ||
| name: "Launch Workflow", | ||
| description: "Launches a new workflow in Ironclad. [See the documentation](https://developer.ironcladapp.com/reference/launch-a-new-workflow)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| ironclad, | ||
| templateId: { | ||
| propDefinition: [ | ||
| ironclad, | ||
| "templateId", | ||
| ], | ||
| reloadProps: true, | ||
| }, | ||
| }, | ||
| async additionalProps() { | ||
| const props = {}; | ||
| if (!this.templateId) { | ||
| return props; | ||
| } | ||
| const { schema } = await this.ironclad.getWorkflowSchema({ | ||
| templateId: this.templateId, | ||
| }); | ||
| for (const [ | ||
| key, | ||
| value, | ||
| ] of Object.entries(schema)) { | ||
| if (!value.readOnly) { | ||
| props[key] = { | ||
| type: value.type === "boolean" | ||
| ? "boolean" | ||
| : value.type === "array" | ||
| ? "string[]" | ||
| : "string", | ||
| label: value.displayName, | ||
| description: getAttributeDescription(value), | ||
| optional: (!(key === "counterpartyName") && !value.displayName.toLowerCase().includes("required")), | ||
| }; | ||
| if (key === "paperSource") { | ||
| props[key].options = [ | ||
| "Counterparty paper", | ||
| "Our paper", | ||
| ]; | ||
| } | ||
| if (key === "recordType") { | ||
| const { recordTypes } = await this.ironclad.getRecordsSchema(); | ||
| props[key].options = Object.values(recordTypes) | ||
| .map((recordType) => recordType.displayName); | ||
| } | ||
| } | ||
| } | ||
| return props; | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| ironclad, | ||
| templateId, | ||
| ...attributes | ||
| } = this; | ||
|  | ||
| const parsedAttributes = {}; | ||
| for (const [ | ||
| key, | ||
| value, | ||
| ] of Object.entries(attributes)) { | ||
| parsedAttributes[key] = parseValue(value); | ||
| } | ||
|  | ||
| try { | ||
| const response = await ironclad.launchWorkflow({ | ||
| $, | ||
| params: { | ||
| useDefaultValues: true, | ||
| }, | ||
| data: { | ||
| template: templateId, | ||
| attributes: parsedAttributes, | ||
| }, | ||
| }); | ||
| $.export("$summary", `Workflow launched successfully with ID ${response.id}`); | ||
| return response; | ||
| } catch (error) { | ||
| const msg = JSON.parse(error.message); | ||
| const { schema } = await ironclad.getWorkflowSchema({ | ||
| templateId, | ||
| }); | ||
| if (msg.code === "MISSING_PARAM") { | ||
| const paramNames = (JSON.parse(msg.param)).map((p) => `\`${schema[p].displayName}\``); | ||
| throw new ConfigurationError(`Please enter or update the following required parameters: ${paramNames.join(", ")}`); | ||
| } | ||
| if (msg.code === "INVALID_PARAM") { | ||
| const paramName = schema[msg.metadata.keyPath].displayName; | ||
| throw new ConfigurationError(`Invalid parameter: \`${paramName}\`. ${msg.message}`); | ||
| } | ||
| throw new ConfigurationError(msg.message); | ||
| } | ||
| }, | ||
| }; | 
        
          
          
            112 changes: 112 additions & 0 deletions
          
          112 
        
  components/ironclad/actions/update-workflow/update-workflow.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,112 @@ | ||
| import ironclad from "../../ironclad.app.mjs"; | ||
| import { ConfigurationError } from "@pipedream/platform"; | ||
| import { | ||
| getAttributeDescription, parseValue, | ||
| } from "../../common/utils.mjs"; | ||
|  | ||
| export default { | ||
| key: "ironclad-update-workflow", | ||
| name: "Update Workflow Metadata", | ||
| description: "Updates the metadata of an existing workflow. [See the documentation]()", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| ironclad, | ||
| workflowId: { | ||
| propDefinition: [ | ||
| ironclad, | ||
| "workflowId", | ||
| ], | ||
| reloadProps: true, | ||
| }, | ||
| comment: { | ||
| type: "string", | ||
| label: "Comment", | ||
| description: "A comment that explains the updates you are making to the workflow", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async additionalProps() { | ||
| const props = {}; | ||
| if (!this.workflowId) { | ||
| return props; | ||
| } | ||
| const { schema } = await this.ironclad.getWorkflow({ | ||
| workflowId: this.workflowId, | ||
| }); | ||
| for (const [ | ||
| key, | ||
| value, | ||
| ] of Object.entries(schema)) { | ||
| if (!value?.readOnly) { | ||
| props[key] = { | ||
| type: value.type === "boolean" | ||
| ? "boolean" | ||
| : value.type === "array" | ||
| ? "string[]" | ||
| : "string", | ||
| label: value.displayName, | ||
| description: getAttributeDescription(value), | ||
| optional: true, | ||
| }; | ||
| if (key === "paperSource") { | ||
| props[key].options = [ | ||
| "Counterparty paper", | ||
| "Our paper", | ||
| ]; | ||
| } | ||
| } | ||
| } | ||
| return props; | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| ironclad, | ||
| workflowId, | ||
| comment, | ||
| ...attributes | ||
| } = this; | ||
|  | ||
| const parsedAttributes = {}; | ||
| for (const [ | ||
| key, | ||
| value, | ||
| ] of Object.entries(attributes)) { | ||
| parsedAttributes[key] = parseValue(value); | ||
| } | ||
|  | ||
| try { | ||
| const response = await ironclad.updateWorkflowMetadata({ | ||
| $, | ||
| workflowId: workflowId, | ||
| data: { | ||
| updates: Object.entries(parsedAttributes).map(([ | ||
| key, | ||
| value, | ||
| ]) => ({ | ||
| action: "set", | ||
| path: key, | ||
| value, | ||
| })), | ||
| comment: comment, | ||
| }, | ||
| }); | ||
| $.export("$summary", `Workflow ${workflowId} updated successfully`); | ||
| return response; | ||
| } catch (error) { | ||
| const msg = JSON.parse(error.message); | ||
| const { schema } = await ironclad.getWorkflow({ | ||
| workflowId, | ||
| }); | ||
| if (msg.code === "MISSING_PARAM") { | ||
| const paramNames = (JSON.parse(msg.param)).map((p) => `\`${schema[p].displayName}\``); | ||
| throw new ConfigurationError(`Please enter or update the following required parameters: ${paramNames.join(", ")}`); | ||
| } | ||
| if (msg.code === "INVALID_PARAM") { | ||
| const paramName = schema[msg.metadata.keyPath].displayName; | ||
| throw new ConfigurationError(`Invalid parameter: \`${paramName}\`. ${msg.message}`); | ||
| } | ||
| throw new ConfigurationError(msg.message); | ||
| } | ||
| }, | ||
| }; | 
  
    
      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,64 @@ | ||
| export function getAttributeDescription({ | ||
| type, displayName, elementType, | ||
| }) { | ||
|         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| const description = `Value of ${displayName}`; | ||
| if (type === "address") { | ||
| return `${description}. Example: \`{ | ||
| "lines": [ | ||
| "325 5th Street", | ||
| "Suite 200" | ||
| ], | ||
| "locality": "San Francisco", | ||
| "region": "California", | ||
| "postcode": "94107", | ||
| "country": "USA" | ||
| }\``; | ||
| } | ||
| if (type === "monetaryAmount") { | ||
| return `${description}. Example: \`{ | ||
| "currency": "USD", | ||
| "amount": 25.37 | ||
| }\``; | ||
| } | ||
| if (type === "date") { | ||
| return `${description}. Example: \`2021-05-11T17:16:53-07:00\``; | ||
| } | ||
| if (type === "duration") { | ||
| return `${description}. Example \`{ | ||
| "years": 1, | ||
| "months": 2, | ||
| "weeks": 3, | ||
| "days": 4 | ||
| }\``; | ||
| } | ||
| if (type === "email") { | ||
| return `${description}. Example: \`[email protected]\``; | ||
| } | ||
| if (type === "array") { | ||
| if (elementType.type === "document") { | ||
| return `${description}. Array of type \`${elementType.type}\`. Example: \`{"url": "https://your.file.server.test/test-doc-1.docx"}\``; | ||
| } | ||
| if (elementType.type === "object") { | ||
| return `${description}. Array of type \`${elementType.type}\`. See the [docs](https://developer.ironcladapp.com/docs/launch-a-workflow#32-create-request-body-attributes) for more information about field types.`; | ||
| } | ||
| return `${description}. Array of type \`${elementType.type}\`.`; | ||
| } | ||
| return description; | ||
| } | ||
|  | ||
| export function parseValue(value) { | ||
| if (!value) { | ||
| return undefined; | ||
| } | ||
| try { | ||
| if (typeof value === "string") { | ||
| return JSON.parse(value); | ||
| } | ||
| if (Array.isArray(value)) { | ||
| return value.map(JSON.parse); | ||
| } | ||
| return value; | ||
| } catch { | ||
| return value; | ||
| } | ||
| } | ||
|         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
      
      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.