Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions components/taxjar/.gitignore

This file was deleted.

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;
},
};
Comment on lines +1 to +98
Copy link
Contributor

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:

  1. The run method should include error handling to gracefully handle API failures
  2. The summary message doesn't verify if response.tax.amount_to_collect exists before accessing it
  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;
+   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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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;
},
};
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({ $ }) {
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;
}
},
};

82 changes: 82 additions & 0 deletions components/taxjar/actions/create-customer/create-customer.mjs
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 components/taxjar/actions/validate-address/validate-address.mjs
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;
},
};
13 changes: 0 additions & 13 deletions components/taxjar/app/taxjar.app.ts

This file was deleted.

8 changes: 8 additions & 0 deletions components/taxjar/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
EXEMPTION_TYPES: [
"wholesale",
"government",
"other",
"non_exempt",
],
};
8 changes: 5 additions & 3 deletions components/taxjar/package.json
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"
}
}
Loading
Loading