Git Product home page Git Product logo

avatax-rest-v2-js-sdk's Introduction

AvaTax Rest V2 Node.js SDK

AvaTax v2 SDK for languages using node.js

Version Build Status Downloads Try on RunKit

Installation

Install the package with:

# using npm 
npm install avatax

# using yarn
yarn add avatax

Usage

Configuration

// es5 import
var Avatax = require('avatax');

// es6/7 import
// import Avatax from 'avatax';

// resolve configuration, credentials and logOptions
const config = {
  appName: 'your-app',
  appVersion: '1.0',
  environment: 'sandbox',
  machineName: 'your-machine-name',
  timeout: 5000, // optional, default 20 min
  logOptions: {
    logEnabled: true, // toggle logging on or off, by default its off.
    logLevel: 3, // logLevel that will be used, Options are LogLevel.Error (0), LogLevel.Warn (1), LogLevel.Info (2), LogLevel.Debug (3)
    logRequestAndResponseInfo: true, // Toggle logging of the request and response bodies on and off.
    logger: myCustomLogger // (OPTIONAL) Custom logger can be passed in that implements the BaseLogger interface (e.g. debug, info, warn, error, and log functions) Otherwise console.log/error etc will be used by default.
  },
  customHttpAgent: new https.Agent({keepAlive: true}), // (OPTIONAL) Define a custom https agent, import https from node to use this constructor. See https://node.readthedocs.io/en/latest/api/https/#https_class_https_agent for more information.
  enableStrictTypeConversion: true // Ensures that all responses returned by the API methods will be type-safe and match the Models explicitly, For Example, the enums will be returned as integer values instead of as Strings as previously were.
};

const creds = {
  username: '<your-username>',
  password: '<your-password>'
};

var client = new Avatax(config).withSecurity(creds);

Tax Calculation

const taxDocument = {
  type: 'SalesInvoice',
  companyCode: 'abc123',
  date: '2017-04-12',
  customerCode: 'ABC',
  purchaseOrderNo: '2017-04-12-001',
  addresses: {
    SingleLocation: {
      line1: '123 Main Street',
      city: 'Irvine',
      region: 'CA',
      country: 'US',
      postalCode: '92615'
    }
  },
  lines: [
    {
      number: '1',
      quantity: 1,
      amount: 100,
      taxCode: 'PS081282',
      itemCode: 'Y0001',
      description: 'Yarn'
    }
  ],
  commit: true,
  currencyCode: 'USD',
  description: 'Yarn'
}

return client.createTransaction({ model: taxDocument })
  .then(result => {
    // response tax document
    console.log(result);
  });

Address Validation

const address = {
  city: 'irvine',
  postalCode: '92615',
  region: 'ca',
  country: 'us'
};

return client.resolveAddress(address)
  .then(result => {
    // address validation result
    console.log(result);
  });

Release Notes

Please see the Github releases for in-depth release notes.

Typescript support

As of version 22.11.0, Typescript support is included in the SDK. Models and Enums included in addition to typing for all of the API methods and parameters. The team welcomes any feedback on this feature.

Models and Enums can be imported into Typescript projects as follows:

import { AddressResolutionModel } from 'avatax/lib/models';
import { AddressCategoryId } from 'avatax/lib/enums';

SDK Development

Adding integration test credentials

Running integration tests will hit the deployed lower environment

Test credentials are resolved in the following order:

  1. Environment variables

The following environment variables will get loaded as test credentials

SANDBOX_USERNAME="your-username"
SANDBOX_PASSWORD="your-password"
  1. Local credentials file

You can also add a local credentials file to the the path "<project_root>/local_creds.json". This file will be gitignored

{
  "username": "your-username",
  "password": "your-password"
}
  1. Static (mock) values

The mocked values are used for unit tests via 'nock'.

The test credentials helper can be found here https://github.com/avadev/AvaTax-REST-V2-JS-SDK/blob/master/test/helpers/load_creds.js

Publish tags upstream

# assuming a tag of v17.5.2 and a remote of 'upstream'
git push upstream v17.5.2

avatax-rest-v2-js-sdk's People

Contributors

akshit-avalara avatar avalara-chriswalker avatar avasachinbaijal avatar benpatterson2 avatar brian-hunter-avalara avatar contygm avatar han8909227 avatar harwinderjit avatar justinsoliz avatar kevinliddle avatar qjavalara avatar rahulv-dev avatar shilpa-khanal avatar shilpakhanal avatar svc-developer avatar ted-spence-avalara avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

avatax-rest-v2-js-sdk's Issues

refundTransaction issue with dates

Hi,

I have a question related to refundTransaction.
We are using this function with refundDate and useTaxDateOverride = true.

So result is that ReturnInvoice is created with both date and taxDate matching refundDate.
Our accounting expects that date is same as refundDate (when it is created and to be reported in that month) and taxDate to match a taxDate from the original SelesInvoice so rates are the same as on original document.

Is it possible to reach this dates to be different with refundTransaction or it should be done with createTransaction?

Using v 20.9.0

Error handling regressed

It looks like version 21.12.0 of this library completely regressed error handling. It was working fine before:

// handle error
if (json.error) {
let ex = new Error(json.error.message);

But someone decided it would be a good idea to add a length check:

// handle error
if (json && json.length>0 && json.error) {
let ex = new Error(json.error.message);

Of course, the response isn't guaranteed to be an array - it might just be a single top-level object, as is the case for what's returned by getTransactionByCode:

image

Solution for now is to pin to 21.10.0 but this seems like a pretty careless release.

19.9.1 published without running the npm build

like: #82

import client from './lib/AvaTaxClient';
       ^^^^^^

SyntaxError: Unexpected identifier
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)

Incorrect types for customer model

It says here that the CustomerModel should be making a number of fields optional but they aren't optional in the TS. Ex. contacts (see screenshot from the linked website).

Based on the sample result I'd say what is defined in the API is correct and the model in this repository is incorrect.

(also please provide the return type for queryCompanies instead of just object)

image

Return response status

In Avalara documentation says:
...AvaTax API call produces an error, it responds using the standard HTTP error response codes

  • 400-499 Client errors
  • 500-599 Server errors

Avalara Doc: Handling Error Messages

But we can not get the response status since Avalara is returning response.json(), so the subsequent then and catch only get the result of response.json() which is the body of the response. Therefore the response status is not visible in the second then

return res.json();

CVE-2022-0235 - node-fetch (peer dependency via isomorphic-fetch)

CVE-2022-0235

Versions of the node-fetch package lower than 2.6.7 are potentially vulnerable to exposure of sensitive information to an unauthorized actor (see GHSA-r683-j2x4-v87g)

The node-fetch package is a peer dependency of the Avatax-REST-V2-JS-SDK package via the isomorphic-fetch package:

"isomorphic-fetch": "^2.2.1"

isomorphic-fetch:
version "2.2.1"
resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9"
dependencies:
node-fetch "^1.0.1"
whatwg-fetch ">=0.10.0"

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ high          โ”‚ node-fetch is vulnerable to Exposure of Sensitive            โ”‚
โ”‚               โ”‚ Information to an Unauthorized Actor                         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Package       โ”‚ node-fetch                                                   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Patched in    โ”‚ >=2.6.7                                                      โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Dependency of โ”‚ isomorphic-fetch                                             โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Path          โ”‚ isomorphic-fetch > node-fetch                                โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ More info     โ”‚ https://www.npmjs.com/advisories/1006899                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Overriding node-fetch to a safe version is not currently an option

Testing with node-fetch version 2.6.7, the following TypeError is encountered TypeError: Cannot read properties of undefined (reading 'content-type') handling responses here:

var contentType = res.headers._headers['content-type'];
var contentLength = res.headers._headers['content-length'];

Would it be possible to prioritize a fix for this vulnerability?

withTimeout() causes Node to hang

I'm calling the taxRatesByAddress method and am successfully getting back a tax rates object, but my application hangs every time. Something is preventing Node from closing.

I used the wtfnode package to investigate. This is the output I received:

^C[WTF Node?] open handles:
- File descriptors: (note: stdio always exists)
  - fd 1 (tty) (stdio)
  - fd 2 (tty) (stdio)
- Timers:
  - (1200000 ~ 20 min) (anonymous) @ /.../node_modules/avatax/lib/utils/withTimeout.js:9

The withTimeout function returns Promise.race(), with two promises in the iterable. The first one is a timer for 20 minutes. It seems to me that this timer is keeping the application open.

Addresses undefined when using the `auditTransaction` function

I updated my SDK and configured the client based on this PR:
#249 (comment)

However, now when I call await avatax.auditTransaction (as shown below) the address is undefined/empty as shown in my screenshots (- note I only show response but it also isn't in request for both reconstructed and original fields of the returned object).

await avatax.auditTransaction({
                    companyCode: companyCode,
                    transactionCode: salesInvoice.code,
                })

image

refundTransaction always errors out because of missing refundDate

The refundTransaction function is failing because of a missing refundDate. When I hit the endpoint directly, it expects this format:

{
    "companyCode",
    "transactionCode",
    "refundDate": "2022-03-11",
    "model": {
        "RefundTransactionModel": { ... }
}

However, the refundTransaction function doesn't send refundDate in the body of the request.

The docs must be incorrect, because refundDate isn't listed as a required param in the body of the request:

It is only listed as a required param within the refundTransactionModel. But I have tried including it just within the refundTransactionModel, and not within the body, and the request fails.

This is an example request where I included refundDate within the refundTransactionModel and it failed because of a missing refundDate.

`createTransaction` returns its `type` property as a `string` instead of the numeric `enum`

The typescript for the SDK says that when you call .createTransaction it should return a transaction model where type is an enum as defined here:
https://github.com/avadev/AvaTax-REST-V2-JS-SDK/blob/master/lib/models/TransactionModel.ts#L56-L60

export declare enum DocumentType {
    SalesOrder = 0,
    SalesInvoice = 1,
    PurchaseOrder = 2,
    PurchaseInvoice = 3,
    ReturnOrder = 4,
    ReturnInvoice = 5,
    InventoryTransferOrder = 6,
    InventoryTransferInvoice = 7,
    ReverseChargeOrder = 8,
    ReverseChargeInvoice = 9,
    CustomsInvoice = 10,
    CustomsOrder = 11,
    Any = -1
}

As you can see the return type of the function createTransaction should populate type as a number.
However, from inspecting the result in the debugger it is actually a string not a number (see screenshot).

This should be fixed (either the type needs to change or the API result should change to match the expected enum).
image

Same issue for status field on the returned transaction (i.e. it uses the string representation instead of the numeric value from the DocumentStatus enum)

restCall contentType

This code looks invalid:

	  var contentType = res.headers._headers['content-type'][0];

I don't see that Headers has a _headers property.
Also, not sure if the case of Content-Type matters, but the HTTP convention is Content-Type (not content-type).

I think it should be:

	  var contentType = res.headers.get('Content-Type');

JSDoc is invalid

The JSDoc is invalid. Consider this example:

  /**
   * Configure this client to use the specified username/password security settings
   *
   * @param  string          username        The username for your AvaTax user account
   * @param  string          password        The password for your AvaTax user account
   * @param  int             accountId       The account ID of your avatax account
   * @param  string          licenseKey      The license key of your avatax account
   * @param  string          bearerToken     The OAuth 2.0 token provided by Avalara Identity
   * @return AvaTaxClient
   */
  withSecurity({ username, password, accountId, licenseKey, bearerToken }) {
...
  }
  • The JSDoc has types (great!), but they are not surrounded by braces, so a processor things there is a parameter called string rather than username.
  • int is not a valid type; it would be number
  • The parameter names do not coincide with the parameters because destructured parameters are consistently used.

The JSDoc should instead be something like:

  /**
   * Configure this client to use the specified username/password security settings
   *
   * @param params
   * @param {string} params.username     The username for your AvaTax user account
   * @param {string} params.password     The password for your AvaTax user account
   * @param {number} params.accountId    The account ID of your avatax account
   * @param {string} params.licenseKey   The license key of your avatax account
   * @param {string} params.bearerToken  The OAuth 2.0 token provided by Avalara Identity
   * @returns {AvaTaxClient}
   */
  withSecurity({ username, password, accountId, licenseKey, bearerToken }) {
...
  }

There are over 300 cases that need to be fixed, but they are mostly trivial changes.

Cleaning up the JSDoc would be a huge step towards supporting TypeScript (#124).

uploadCertificateImage does not work as intended

When trying to upload a certificate image using the node client i get the following error message:

  code: 'InvalidRequestContentType',
  target: 'HttpRequest',
  details: [
    {
      code: 'InvalidRequestContentType',
      number: 1217,
      message: 'The request content type is invalid.',
      description: "The request content type must be either 'multipart/form-data' or empty string.",
      faultCode: 'Client',
      helpLink: 'http://developer.avalara.com/avatax/errors/InvalidRequestContentType',
      severity: 'Error'
    }
  ]

it looks like the rest client is always set to send application/json

i have had to handle this manually:

    const file = fs.readFileSync(path.join(__dirname, filename));

    if (file) {
      const formData = new FormData();

      formData.append("file", new Blob([file]));

      return fetch(
        `https://sandbox-rest.avatax.com/api/v2/companies/${1}/certificates/${
         certificateId
        }/attachment`,
        {
          method: "POST",
          body: formData,
          headers: {
            Authorization: createBasicAuthHeader(creds.accountId, creds.licenseKey),
          },
        }
      )
        .then((response) => response.json())
        .catch((err) => console.log(err));

Doc: Missing comma (,) in the README.md file for configuration

Hi Team,

This is not big issue, just recommendation to make this library more useful.

const config = {
  appName: 'your-app',
  appVersion: '1.0',
  environment: 'sandbox',
  machineName: 'your-machine-name'
  timeout: 5000, // optional, default 20 min
  logOptions: {
    logEnabled: true, // toggle logging on or off, by default its off.
    logLevel: 3, // logLevel that will be used, Options are LogLevel.Error (0), LogLevel.Warn (1), LogLevel.Info (2), LogLevel.Debug (3)
    logRequestAndResponseInfo: true, // Toggle logging of the request and response bodies on and off.
    logger: myCustomLogger // (OPTIONAL) Custom logger can be passed in that implements the BaseLogger interface (e.g. debug, info, warn, error, and log functions) Otherwise console.log/error etc will be used by default.
  },
  customHttpAgent: new https.Agent({keepAlive: true}), // (OPTIONAL) Define a custom https agent, import https from node to use this constructor. See https://node.readthedocs.io/en/latest/api/https/#https_class_https_agent for more information.
  enableStrictTypeConversion: true // Ensures that all responses returned by the API methods will be type-safe and match the Models explicitly, For Example, the enums will be returned as integer values instead of as Strings as previously were.
};

machineName: 'your-machine-name'

Missing comma here. :)

Thanks!

BUG: downloadTaxRatesByZipCode errors

downloadTaxRatesByZipCode errors

(node:56816) UnhandledPromiseRejectionWarning: #<Object>
(node:56816) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:56816) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I believe when response is csv, it still tried to parse it as json and parsing fails.

https://github.com/avadev/AvaTax-REST-V2-JS-SDK/blob/master/lib/AvaTaxClient.js#L92

https://github.com/avadev/AvaTax-REST-V2-JS-SDK/blob/master/lib/AvaTaxClient.js#L96

You forced us to do two `await res.text()`, we got `body used already for:...`

Hello

We're updating from 22.10.0 to 23.2.0

Our code:
image

We have 2 issues here.

  1. Major one is that we get:
    body used already for: http://localhost:2901/api/v2/taxratesbyzipcode/download/2023-03-14 at Response.consumeBody (/app/node_modules/node-fetch/lib/index.js:344:30)

It happens because you have extra res.text() here
image

If we comment it, everything works.

  1. The second issue is minor type issue, we fixed it on our side (First screenshot, { date: updated as unknown as Date }). date param should be string instead of Date.

Could you please take a look?

Thanks in advance!!

Split shipment ShipFrom value

Hello,
In case of a split shipment (some items are being shipped from a US warehouse and some from a EU warehouse), how do I send the multiple ShipFrom information?

Also, how do I make the connection in the TaxDocument between which item in the order is shipped from where?
Are there any guides in regards to split-shipments that I can consult?

I looked for some on the Avalara website but I came up empty, if you can point me in the right direction please, that'd be brilliant.

Thank you

Did Not Build Latest Version

Hello,

The latest version of this library (you get from npm install avatax) is not built correctly and the source code is missing the entire libs folder so none of the examples posted on the website are working. I've downgraded my version to 21.8.0 and all the code is present. Can you please double check this and see what's going on? Thanks!

Dave

19.3.0 published without running the npm build

v19.3.0 was published without running the build script causing the package to fail on Node v10 and earlier

/home/circleci/project/node_modules/avatax/index.js:6
import client from './lib/AvaTaxClient';
^^^^^^

SyntaxError: Unexpected token import

Document usage of customHttpAgent parameter

It looks like support for adding a customHttpAgent when initializing the client was added in this PR in response to this request. The configuration documented in the README does not show this field or explain what it is or what it's used for, it would be helpful to update that especially since ava-typescript won't let you initialize the client without passing that information.

Additionally, can that field be made optional for those who don't need to pass a custom agent?

Resolve address throws error from BigInt

When resolving an address like this:

{
	"line1": "1510 Foster Circle",
	"line2": "Algonquin",
 	"textCase": "Mixed",
 	"city": "Illinois",
 	"region": "IL",
 	"country": "US",
 	"postalCode": "60102"
}

We get this error from the SDK.

SyntaxError: Cannot convert 42.144481999999996 to a BigInt
    at BigInt (<anonymous>)
    at number (/app/node_modules/json-bigint/lib/parse.js:215:15)
    at value (/app/node_modules/json-bigint/lib/parse.js:397:41)
    at object (/app/node_modules/json-bigint/lib/parse.js:367:27)

Update 1

This issue is related to this sidorares/json-bigint#49

Model required on voidTransaction

On the voidTransaction function, model is marked as optional, but if not provided it throws an error...

    voidTransaction({ companyCode, transactionCode, documentType, include, model }: {
        companyCode: string;
        transactionCode: string;
        documentType?: Enums.DocumentType;
        include?: string;
        model?: Models.VoidTransactionModel;
    }): Promise<Models.TransactionModel>;
Error: A required model was not provided.
code: 'ModelRequiredException',
  target: 'IncorrectData',
  details: [
    {
      code: 'ModelRequiredException',
      number: 38,
      message: 'A required model was not provided.',
      description: 'Please verify that your request included a request body in valid JSON format.',
      faultCode: 'Client',
      helpLink: 'https://developer.avalara.com/avatax/errors/ModelRequiredException',
      severity: 'Exception'
    }
  ]

`voidTransaction` always throws when deleting a transaction even though it successfully deletes it

When I try to delete an uncommitted transaction this code always throws an error (even though the transaction gets successfully deleted). The error that is thrown indicates that no transaction was found. This probably is because it tries to return the transaction that no longer exists. The correct behaviour based on the typescript definitions should be to return what the transaction looked like before it was deleted (if you don't intend to do that then this should at least return void (when deleting) otherwise it is hard to differentiate between actual errors and ones caused by this bug).

   await avatax.voidTransaction({
             transactionCode: invoice.code,
             model: {
                  // For descriptions of the codes see:
                  // https://developer.avalara.com/erp-integration-guide/sales-tax-badge/transactions/voiding-documents/
                  code: VoidReasonCode.DocDeleted,
   },
  })

Can't create new client with Typescript - Docs example doesn't work

Hi,

trying the following doesn't work

import Avatax from 'avatax';

const client = new Avatax(config)

Getting an error This expression is not constructable.

Trying as const client = new Avatax.default(config) works for TS lint but then fail on runtime becasue TypeError: Avatax.default is not a constructor

How can I create a new client?

Currently I do the following (which works):

import Avatax from 'avatax';
import type AvaTaxClient from 'avatax/lib/AvaTaxClient.js';

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const client: AvaTaxClient.default = new Avatax(config)

Could not find a declaration file for module 'node-fetch'

with the latest version 23.3.0, i am getting the above type error when trying to build my project. the error is originating in this file node_modules/avatax/lib/utils/logObject.d.ts i was not getting this error on 22.11.1

here is my tsconfig file:

{
  "compilerOptions": {
    "target": "esnext",
    "lib": ["es6", "dom", "dom.iterable", "esnext"],
    "module": "commonjs",
    "moduleResolution": "node",
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "allowJs": false,
    "baseUrl": ".",
    "outDir": "dist",
    "sourceMap": true,
    "esModuleInterop": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "resolveJsonModule": true,

    "paths": {
      "@/*": ["./src/*"]
    },
  },

  "include": ["./**/*"],

  "exclude": ["node_modules/**/*"]
}

restCall error handler

This code looks invalid:

        // handle error
        if (json.error) {
          let ex = new Error(json.error.message);
          ex.code = json.error.code;
          ex.target = json.error.target;
          ex.details = json.error.details;
          throw ex;
        } else {
          return json;
        }

Specifically, code, target, and details are not properties of an Error object.

TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.

Hi,

When I tried the taxRatesByAddress API on Angular 4, it shows: the following error

TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.

The same method works fine from Node.JS backend application. It turns out that HEAD or GET requests should not have a body, see JakeChampion/fetch#402, changing from null to undefined resolves the issue.

https://github.com/avadev/AvaTax-REST-V2-JS-SDK/blob/master/lib/AvaTaxClient.js#L2788

Error parsing HTML as JSON

When API is down the server responds an HTML, then an unfriendly error explodes when trying to parse response as JSON here:

.then(res => res.json())

Error

{"error":{"message":"Unexpected token < in JSON at position 0","stack":"SyntaxError: Unexpected token < in JSON at position 0\n at JSON.parse ()\n at /node_modules/node-fetch/lib/body.js:48:1\n at \n at process._tickCallback (internal/process/next_tick.js:188:7)","url":null,"method":null,"data":null}}

HTML

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8" />
    <title>500 Internal Server Error</title>
    <style type="text/css">
        body {
            background-color: white;
            color: #111111;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 2em 4em;
        }

        footer a {
            color: darkblue;
            text-decoration: none;
            font-weight: bolder;
        }

        #header {
            margin-bottom: 2.5em;
        }

        .stacktrace pre {
            display: inline;
        }

        .faded {
            color: #999999;
            font-weight: normal;
        }

        div.message {
            margin-top: 2.5em;
            padding: 0.3em 1em;
            border-left: 0.25em solid red;
        }

        .light {
            font-size: 1.3em;
            font-weight: lighter;
        }

        .heavy {
            font-size: 1.5em;
        }

        .exception {
            color: red;
        }

        .stacktrace {
            padding-top: 0.3em;
            padding-left: 2em;
            display: block;
            font-weight: bold;
        }

        .codeSnippet {
            margin-left: 2em;
            margin-top: 1em;
            margin-bottom: 1em;
            display: inline-block;
            border-top: 0.2em solid #cccccc;
            border-bottom: 0.2em solid #cccccc;
            color: black;
        }

        .codeSnippet div:nth-of-type(2n) {
            background-color: #f0f0f0;
        }

        .codeSnippet div:nth-of-type(2n + 1) {
            background-color: #f6f6f6;
        }

        .codeSnippet div.filename {
            font-weight: bold;
            background-color: white;
            margin: 0.6em;
        }

        .codeSnippet div.line {
            padding: 0.2em;
            line-height: 1em;
        }

        .codeSnippet div.line .line-number {
            color: #999999;
            text-align: right;
            margin-right: 0.5em;
        }

        .codeSnippet div.error {
            color: red;
            font-weight: bolder;
            background-color: #ffeda7;
        }

        .codeSnippet code {
            white-space: pre;
        }

        .rawExceptionBlock {
            margin-top: 1em;
            margin-left: 1em;
        }

        #rawException {
            display: none;
        }

        footer {
            margin-top: 2em;
            font-size: smaller;
            font-weight: lighter;
        }
    </style>
    <script type="text/javascript">
        function showRawException() {
            var div = document.getElementById('rawException');
            div.style.display = 'inline-block';
            div.scrollIntoView(true);
        }
    </script>
</head>
<body>

    <div id="header">
        <div style="font-size: 6em; display: inline-block;">
            :(
        </div>
        <div style="display: inline-block; padding-left: 3em;">
            <span style="font-size: 2em;">Oops.</span><br />
            <span style="font-size: 1.65em; font-weight: lighter;">500 Internal Server Error</span>
        </div>
    </div>

    <div class="message">
    <span class="heavy">An error occurred while starting the application.</span><br />
</div>
</body>

Cant't found types to use it with typescript

I am using typescript and install avatax, but when I import it i got the error

Could not find a declaration file for module 'avatax'. 'node_modules/avatax/index.js' implicitly has an 'any' type.
  Try `npm install @types/avatax` if it exists or add a new declaration (.d.ts) file containing `declare module 'avatax';`ts(7016)

If i try npm install @types/avatax the response is no found.

Could you provide .d.ts file with typescript types

Questionable empty default parameter values

A number of methods have a questionable empty default parameter value, like this:

  /**
   * Reset this account's license key
   *
   * Resets the existing license key for this account to a new key.
     *  
     * To reset your account, you must specify the ID of the account you wish to reset and confirm the action.
     *  
     * This API is only available to account administrators for the account in question, and may only be called after
     * an account has been activated by reading and accepting Avalara's terms and conditions. To activate your account
     * please log onto the AvaTax website or call the `ActivateAccount` API.
     *  
     * You can only reset license with 'Default' license key name. 
     * Resetting a license key cannot be undone. Any previous license keys will immediately cease to work when a new key is created.
     *  
     * When you call this API, all account administrators for this account will receive an email with the newly updated license key.
     * The email will specify which user reset the license key and it will contain the new key to use to update your connectors.
     * Note: The reset license key functionality will only be available for existing active license key i.e. when you reset license key for the account, the Default license key will be reset.The reset license key functionality is not available for newly created license keys i.e. license keys other than Default
     * 
     * ### Security Policies
     * 
     * * This API requires one of the following user roles: AccountAdmin, Registrar, SiteAdmin, SSTAdmin, SystemAdmin, TechnicalSupportAdmin.
   *
   * 
     * @param int id The ID of the account you wish to update.
     * @param object model A request confirming that you wish to reset the license key of this account.
   * @return object
   */
  accountResetLicenseKey({ id, model } = {}) {
    var path = this.buildUrl({
      url: `/api/v2/accounts/${id}/resetlicensekey`,
      parameters: {}
    });
    return this.restCall({ url: path, verb: 'post', payload: model });
  }

In this example, the documentation states that "you must specify the ID of the account", so then why would an empty default value (= {}) make sense at all?

TypeScript will complain that:

'{}' is missing the following properties from type '{ id: number; model: object; }': id, model ts(2739)

I suggest reviewing them and removing them. Ultimately, the cleaner code will help with supporting TypeScript (#124).

Why is `model` now optional in all the API functions?

I noticed that in the different methods you mark model as optional but does it really make sense for model to be optional in the various methods especially this one (see example below) if we pass in undefined for the model what customers are being created? I know in the API docs body is optional for most/all of the methods but that seems like an error to me?
Ex.

     /*
       * @param {number} companyId The unique ID number of the company that recorded this customer
       * @param {Models.CustomerModel[]} model The list of customer objects to be created
     * @return {Models.CustomerModel[]}
     */
    createCustomers({ companyId, model }: {
        companyId: number;
        model?: Models.CustomerModel[];
    }): Promise<Array<Models.CustomerModel>

Types for the SDK

I haven't found any types for this SDK, so I can't use it because I don't know which methods it has, how use it. Please provide it, because the library has only one file AvaTaxClient.js with the not readable code something like this

*/},{key:'queryTaxRules',value:function queryTaxRules(){var _ref318=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{},filter=_ref318.filter,include=_ref318.include,top=_ref318.top,skip=_ref318.skip,orderBy=_ref318.orderBy;var path=this.buildUrl({url:'/api/v2/taxrules',parameters:{$filter:filter,$include:include,$top:top,$skip:skip,$orderBy:orderBy}});var strClientId=this.appNM+'; '+this.appVer+'; JavascriptSdk; 22.3.0; '+this.machineNM;return this.restCall({url:path,verb:'get',payload:null,clientId:strClientId});}/**

v19.3.0 ESModules - Unexpected token import

v19.3.0 seemed to switch to esmodules which makes this no longer compatible with Node without the use of Babel. My guess is this is a release/packaging issue

/home/circleci/project/node_modules/avatax/index.js:6
import client from './lib/AvaTaxClient';
^^^^^^

SyntaxError: Unexpected token import

How to pass keepAlive agent?

Can we add support to pass a custom http agent in the config.

For example:

let customAgent = new http.Agent({keepAlive: true});

const config = {
  appName: 'your-app',
  appVersion: '1.0',
  environment: 'sandbox',
  machineName: 'your-machine-name'
  timeout: 5000 // optional, default 20 min
  customHttpAgent: customAgent
};

const creds = {
  username: '<your-username>',
  password: '<your-password>'
};

var client = new Avatax(config).withSecurity(creds);


assert.equal(config.customHttpAgent, customAgent);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.