Skip to content
Open
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
24 changes: 13 additions & 11 deletions lib/AvaTaxClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
* @author Ted Spence <[email protected]>
* @copyright 2004-2018 Avalara, Inc.
* @license https://www.apache.org/licenses/LICENSE-2.0
* @version 21.1.1
* @version 21.1.2
* @link https://github.com/avadev/AvaTax-REST-V2-JS-SDK
*/

import fetch from 'isomorphic-fetch';
import { createBasicAuthHeader } from './utils/basic_auth';
import { withTimeout } from './utils/withTimeout';
var JSONbig = require('json-bigint')({ useNativeBigInt: true });

export default class AvaTaxClient {
/**
Expand All @@ -42,7 +43,7 @@ export default class AvaTaxClient {
appName +
'; ' +
appVersion +
'; JavascriptSdk; 21.1.1; ' +
'; JavascriptSdk; 21.1.2; ' +
machineName;
}

Expand Down Expand Up @@ -85,13 +86,14 @@ export default class AvaTaxClient {
},
body: JSON.stringify(payload)
})).then(res => {
var contentType = res.headers._headers['content-type'][0];
var contentType = res.headers._headers['content-type'][0];

if (contentType === 'application/vnd.ms-excel' || contentType === 'text/csv') {
return res;
}
return res.json();
}).then(json => {
return res.text();
}).then(text => {
var json = JSONbig.parse(text);
// handle error
if (json.error) {
let ex = new Error(json.error.message);
Expand Down Expand Up @@ -763,7 +765,7 @@ export default class AvaTaxClient {
*
* Marks the in progress batch identified by this URL as cancelled.
*
* Only JSON batches can be cancelled. If you attempt to cancel a file batch, you will receive an error message.
* Only JSON batches can be cancelled. If you attempt to cancel a file batch, you will receive an error message.
*
* Only in progress batches can be cancelled. If you attempt to cancel a batch that its status is not Waiting or Processing, you will receive an error message.
* Cancelling an in progress batch does not delete any transactions that were created before the cancellation.
Expand Down Expand Up @@ -1745,7 +1747,7 @@ export default class AvaTaxClient {
* @param object file The exemption certificate file you wanted to upload. Accepted formats are: PDF, JPEG, TIFF, PNG.
* @return string
*/
uploadCertificateImage({ companyId, id, file } = {}) {
uploadCertificateImage({ companyId, id } = {}) {
var path = this.buildUrl({
url: `/api/v2/companies/${companyId}/certificates/${id}/attachment`,
parameters: {}
Expand Down Expand Up @@ -2259,7 +2261,7 @@ export default class AvaTaxClient {
*
* @return FetchResult
*/
listMrsCompanies({ } = {}) {
listMrsCompanies() {
var path = this.buildUrl({
url: `/api/v2/companies/mrs`,
parameters: {}
Expand Down Expand Up @@ -3623,7 +3625,7 @@ export default class AvaTaxClient {
*
* @return FetchResult
*/
listCrossBorderSections({ } = {}) {
listCrossBorderSections() {
var path = this.buildUrl({
url: `/api/v2/definitions/crossborder/sections`,
parameters: {}
Expand Down Expand Up @@ -10808,7 +10810,7 @@ export default class AvaTaxClient {
*
* @return FetchResult
*/
listMySubscriptions({ } = {}) {
listMySubscriptions() {
var path = this.buildUrl({
url: `/api/v2/utilities/subscriptions`,
parameters: {}
Expand Down Expand Up @@ -10843,7 +10845,7 @@ export default class AvaTaxClient {
*
* @return object
*/
ping({ } = {}) {
ping() {
var path = this.buildUrl({
url: `/api/v2/utilities/ping`,
parameters: {}
Expand Down
Loading