diff --git a/components/taxjar/.gitignore b/components/taxjar/.gitignore deleted file mode 100644 index ec761ccab7595..0000000000000 --- a/components/taxjar/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.js -*.mjs -dist \ No newline at end of file diff --git a/components/taxjar/actions/calculate-sales-tax/calculate-sales-tax.mjs b/components/taxjar/actions/calculate-sales-tax/calculate-sales-tax.mjs new file mode 100644 index 0000000000000..f7c223c1d2d5f --- /dev/null +++ b/components/taxjar/actions/calculate-sales-tax/calculate-sales-tax.mjs @@ -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; + }, +}; diff --git a/components/taxjar/actions/create-customer/create-customer.mjs b/components/taxjar/actions/create-customer/create-customer.mjs new file mode 100644 index 0000000000000..6a7eee31accc1 --- /dev/null +++ b/components/taxjar/actions/create-customer/create-customer.mjs @@ -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; + }, +}; diff --git a/components/taxjar/actions/validate-address/validate-address.mjs b/components/taxjar/actions/validate-address/validate-address.mjs new file mode 100644 index 0000000000000..89505788a04de --- /dev/null +++ b/components/taxjar/actions/validate-address/validate-address.mjs @@ -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; + }, +}; diff --git a/components/taxjar/app/taxjar.app.ts b/components/taxjar/app/taxjar.app.ts deleted file mode 100644 index aa7502e2e0953..0000000000000 --- a/components/taxjar/app/taxjar.app.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defineApp } from "@pipedream/types"; - -export default defineApp({ - type: "app", - app: "taxjar", - propDefinitions: {}, - methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); - }, - }, -}); \ No newline at end of file diff --git a/components/taxjar/common/constants.mjs b/components/taxjar/common/constants.mjs new file mode 100644 index 0000000000000..cce9f957f5bf6 --- /dev/null +++ b/components/taxjar/common/constants.mjs @@ -0,0 +1,8 @@ +export default { + EXEMPTION_TYPES: [ + "wholesale", + "government", + "other", + "non_exempt", + ], +}; diff --git a/components/taxjar/package.json b/components/taxjar/package.json index a3591d87e42fa..acb7987e41ab4 100644 --- a/components/taxjar/package.json +++ b/components/taxjar/package.json @@ -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 (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } } diff --git a/components/taxjar/taxjar.app.mjs b/components/taxjar/taxjar.app.mjs new file mode 100644 index 0000000000000..b523b278dbddc --- /dev/null +++ b/components/taxjar/taxjar.app.mjs @@ -0,0 +1,142 @@ +import { axios } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + +export default { + type: "app", + app: "taxjar", + propDefinitions: { + customerId: { + type: "string", + label: "Customer ID", + description: "Unique identifier for the customer", + }, + exemptionType: { + type: "string", + label: "Exemption Type", + description: "The type of tax exemption for the customer", + options: constants.EXEMPTION_TYPES, + }, + name: { + type: "string", + label: "Name", + description: "The name of the customer", + }, + country: { + type: "string", + label: "Country", + description: "The two-letter ISO country code, i.e.: `US`", + }, + state: { + type: "string", + label: "State", + description: "The two-letter ISO state code, i.e.: `CA`", + }, + zip: { + type: "string", + label: "Zip", + description: "The ZIP code of the customer's primary address, i.e.: `92093`", + }, + city: { + type: "string", + label: "City", + description: "The city of the customer's primary address, i.e.: `La Jolla`", + }, + street: { + type: "string", + label: "Street", + description: "The street of the customer's primary address, i.e.: `9500 Gilman Drive`", + }, + fromCountry: { + type: "string", + label: "From Country", + description: "The two-letter ISO country code of the country where the order shipped from, i.e.: `US`", + }, + fromZip: { + type: "string", + label: "From Zip", + description: "The postal code where the order shipped from, i.e.: `92093`", + }, + fromState: { + type: "string", + label: "From State", + description: "The two-letter ISO state code where the order shipped from, i.e.: `CA`", + }, + fromCity: { + type: "string", + label: "From City", + description: "The city where the order shipped from, i.e.: `La Jolla`", + }, + fromStreet: { + type: "string", + label: "From Street", + description: "The street address where the order shipped from, i.e.: `9500 Gilman Drive`", + }, + toCountry: { + type: "string", + label: "To Country", + description: "The two-letter ISO country code of the country where the order shipped to, i.e.: `US`", + }, + toZip: { + type: "string", + label: "To Zip", + description: "The postal code where the order shipped to, i.e.: `92093`", + }, + toState: { + type: "string", + label: "To State", + description: "The two-letter ISO state code where the order shipped yo, i.e.: `CA`", + }, + amount: { + type: "string", + label: "Amount", + description: "Total amount of the order, excluding shipping", + }, + shipping: { + type: "string", + label: "Shipping", + description: "Total amount of shipping for the order", + }, + }, + methods: { + _baseUrl() { + return "https://api.taxjar.com/v2"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + Authorization: `Bearer ${this.$auth.api_key}`, + ...headers, + }, + }); + }, + async createCustomer(args = {}) { + return this._makeRequest({ + path: "/customers", + method: "post", + ...args, + }); + }, + async calculateSalesTax(args = {}) { + return this._makeRequest({ + path: "/taxes", + method: "post", + ...args, + }); + }, + async validateAddress(args = {}) { + return this._makeRequest({ + path: "/addresses/validate", + method: "post", + ...args, + }); + }, + }, +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 271a9e7281879..64f8411030993 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12460,7 +12460,11 @@ importers: specifier: ^1.6.0 version: 1.6.6 - components/taxjar: {} + components/taxjar: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/td_ameritrade: {}