- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.5k
[Components] taxjar #13392 #15907
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
                    [Components] taxjar #13392 #15907
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            2 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    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 was deleted.
      
      Oops, something went wrong.
      
    
  
        
          
          
            98 changes: 98 additions & 0 deletions
          
          98 
        
  components/taxjar/actions/calculate-sales-tax/calculate-sales-tax.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,98 @@ | ||
| import app from "../../taxjar.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "taxjar-calculate-sales-tax", | ||
| name: "Calculate Sales Tax", | ||
| description: "Shows the sales tax that should be collected for a given order. [See the documentation](https://developers.taxjar.com/api/reference/#taxes)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| exemptionType: { | ||
| propDefinition: [ | ||
| app, | ||
| "exemptionType", | ||
| ], | ||
| }, | ||
| fromCountry: { | ||
| propDefinition: [ | ||
| app, | ||
| "fromCountry", | ||
| ], | ||
| }, | ||
| fromZip: { | ||
| propDefinition: [ | ||
| app, | ||
| "fromZip", | ||
| ], | ||
| }, | ||
| fromState: { | ||
| propDefinition: [ | ||
| app, | ||
| "fromState", | ||
| ], | ||
| }, | ||
| fromCity: { | ||
| propDefinition: [ | ||
| app, | ||
| "fromCity", | ||
| ], | ||
| }, | ||
| fromStreet: { | ||
| propDefinition: [ | ||
| app, | ||
| "fromStreet", | ||
| ], | ||
| }, | ||
| toCountry: { | ||
| propDefinition: [ | ||
| app, | ||
| "toCountry", | ||
| ], | ||
| }, | ||
| toZip: { | ||
| propDefinition: [ | ||
| app, | ||
| "toZip", | ||
| ], | ||
| }, | ||
| toState: { | ||
| propDefinition: [ | ||
| app, | ||
| "toState", | ||
| ], | ||
| }, | ||
| amount: { | ||
| propDefinition: [ | ||
| app, | ||
| "amount", | ||
| ], | ||
| }, | ||
| shipping: { | ||
| propDefinition: [ | ||
| app, | ||
| "shipping", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.app.calculateSalesTax({ | ||
| $, | ||
| data: { | ||
| exemption_type: this.exemptionType, | ||
| from_country: this.fromCountry, | ||
| from_zip: this.fromZip, | ||
| from_state: this.fromState, | ||
| from_city: this.fromCity, | ||
| from_street: this.fromStreet, | ||
| to_country: this.toCountry, | ||
| to_zip: this.toZip, | ||
| to_state: this.toState, | ||
| amount: this.amount, | ||
| shipping: this.shipping, | ||
| }, | ||
| }); | ||
| $.export("$summary", `Successfully calculated sales tax. Amount to collect: ${response.tax.amount_to_collect}`); | ||
| return response; | ||
| }, | ||
| }; | ||
        
          
          
            82 changes: 82 additions & 0 deletions
          
          82 
        
  components/taxjar/actions/create-customer/create-customer.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,82 @@ | ||
| import app from "../../taxjar.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "taxjar-create-customer", | ||
| name: "Create Customer", | ||
| description: "Creates a new customer at TaxJar. [See the documentation](https://developers.taxjar.com/api/reference/#post-create-a-customer)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| customerId: { | ||
| propDefinition: [ | ||
| app, | ||
| "customerId", | ||
| ], | ||
| }, | ||
| exemptionType: { | ||
| propDefinition: [ | ||
| app, | ||
| "exemptionType", | ||
| ], | ||
| }, | ||
| name: { | ||
| propDefinition: [ | ||
| app, | ||
| "name", | ||
| ], | ||
| }, | ||
| country: { | ||
| propDefinition: [ | ||
| app, | ||
| "country", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| state: { | ||
| propDefinition: [ | ||
| app, | ||
| "state", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| zip: { | ||
| propDefinition: [ | ||
| app, | ||
| "zip", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| city: { | ||
| propDefinition: [ | ||
| app, | ||
| "city", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| street: { | ||
| propDefinition: [ | ||
| app, | ||
| "street", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.app.createCustomer({ | ||
| $, | ||
| data: { | ||
| customer_id: this.customerId, | ||
| exemption_type: this.exemptionType, | ||
| name: this.name, | ||
| country: this.country, | ||
| state: this.state, | ||
| zip: this.zip, | ||
| city: this.city, | ||
| street: this.street, | ||
| }, | ||
| }); | ||
| $.export("$summary", `Successfully created customer with ID ${this.customerId}`); | ||
| return response; | ||
| }, | ||
| }; | 
        
          
          
            62 changes: 62 additions & 0 deletions
          
          62 
        
  components/taxjar/actions/validate-address/validate-address.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,62 @@ | ||
| import app from "../../taxjar.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "taxjar-validate-address", | ||
| name: "Validate Address", | ||
| description: "Validates a customer address and returns back a collection of address matches. [See the documentation](https://developers.taxjar.com/api/reference/#post-validate-an-address)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| country: { | ||
| propDefinition: [ | ||
| app, | ||
| "country", | ||
| ], | ||
| description: "The two-letter ISO country code, i.e.: `US`. At this time only US addresses can be validated", | ||
| optional: true, | ||
| }, | ||
| state: { | ||
| propDefinition: [ | ||
| app, | ||
| "state", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| zip: { | ||
| propDefinition: [ | ||
| app, | ||
| "zip", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| city: { | ||
| propDefinition: [ | ||
| app, | ||
| "city", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| street: { | ||
| propDefinition: [ | ||
| app, | ||
| "street", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.app.validateAddress({ | ||
| $, | ||
| data: { | ||
| country: this.country, | ||
| state: this.state, | ||
| zip: this.zip, | ||
| city: this.city, | ||
| street: this.street, | ||
| }, | ||
| }); | ||
| $.export("$summary", `Successfully sent the request and found ${response.addresses.length} address matches`); | ||
| 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,8 @@ | ||
| export default { | ||
| EXEMPTION_TYPES: [ | ||
| "wholesale", | ||
| "government", | ||
| "other", | ||
| "non_exempt", | ||
| ], | ||
| }; | 
  
    
      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,16 +1,18 @@ | ||
| { | ||
| "name": "@pipedream/taxjar", | ||
| "version": "0.0.2", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream TaxJar Components", | ||
| "main": "dist/app/taxjar.app.mjs", | ||
| "main": "taxjar.app.mjs", | ||
| "keywords": [ | ||
| "pipedream", | ||
| "taxjar" | ||
| ], | ||
| "files": ["dist"], | ||
| "homepage": "https://pipedream.com/apps/taxjar", | ||
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.0.3" | ||
| } | ||
| } | 
      
      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.
  
    
  
    
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.
🛠️ Refactor suggestion
Enhance error handling and add validation checks
The overall structure of this action is well-organized and follows Pipedream's component model correctly. However, there are some improvements needed for robustness:
response.tax.amount_to_collectexists before accessing itasync run({ $ }) { - const response = await this.app.calculateSalesTax({ - $, - data: { - exemption_type: this.exemptionType, - from_country: this.fromCountry, - from_zip: this.fromZip, - from_state: this.fromState, - from_city: this.fromCity, - from_street: this.fromStreet, - to_country: this.toCountry, - to_zip: this.toZip, - to_state: this.toState, - amount: this.amount, - shipping: this.shipping, - }, - }); - $.export("$summary", `Successfully calculated sales tax. Amount to collect: ${response.tax.amount_to_collect}`); - return response; + try { + const response = await this.app.calculateSalesTax({ + $, + data: { + exemption_type: this.exemptionType, + from_country: this.fromCountry, + from_zip: this.fromZip, + from_state: this.fromState, + from_city: this.fromCity, + from_street: this.fromStreet, + to_country: this.toCountry, + to_zip: this.toZip, + to_state: this.toState, + amount: this.amount, + shipping: this.shipping, + }, + }); + + const amountToCollect = response?.tax?.amount_to_collect || 0; + $.export("$summary", `Successfully calculated sales tax. Amount to collect: ${amountToCollect}`); + return response; + } catch (error) { + $.export("$summary", "Failed to calculate sales tax"); + throw error; + } },📝 Committable suggestion