bhushankummar / amazon-mws

Amazon MWS NodeJS Wrapper
MIT License
197 stars 78 forks source link

Several problems with how financial events are parsed #124

Closed jakeleventhal closed 4 years ago

jakeleventhal commented 4 years ago

I have code to parse different financial events returned from the list financial events api. Here is one of my functions for the network commingling transaction event list:

const processNetworkComminglingTransactionEventList = async (
  marketplace,
  updates,
  networkComminglingTransactionEventList
) => {
  if (networkComminglingTransactionEventList.NetworkComminglingTransactionEvent) {
    _.castArray(networkComminglingTransactionEventList.NetworkComminglingTransactionEvent)
      .forEach(({ TransactionType, TaxExclusiveAmount }) => {
        if (TransactionType in updates.OtherTransactions) {
          updates.OtherTransactions[TransactionType] += Number(TaxExclusiveAmount.CurrencyAmount);
        } else {
          updates.OtherTransactions[TransactionType] = Number(TaxExclusiveAmount.CurrencyAmount);
        }
      });
  }
};

I have many similar functions for different financial event types but there are two issues that my code has to account for:

  1. I always have to cast values to numbers
  2. I have to use lodash's castArray function since data that is supposed to get returned as an array gets returned as an object if there is only one item in the array.

I think it makes sense the amazon-mws library would take care of these things for the user instead of the other way around.

bhushankummar commented 4 years ago

@jakeleventhal Which MWS CAll are you using?

jakeleventhal commented 4 years ago
mws.finances.search({
  Action: 'ListFinancialEvents',
  MWSAuthToken: mwsAuthToken,
  PostedAfter: moment(startDate).toISOString(),
  PostedBefore: endDate && moment(endDate).toISOString(),
  SellerId: sellerId,
  Version: '2015-05-01'
});
jakeleventhal commented 4 years ago

Also, perhaps this library should allow moment.js dates to be used (automatically convert them to iso strings).

It would also be cool if all calls were parametrized like:

mws.finances.listFinancialEvents(sellerId, mwsAuthToken, postedBefore, postedAfter, nextToken);

Things like Action can be just function names and things like Version are static and shouldn't have to be included in every call by the user.

bhushankummar commented 4 years ago

@jakeleventhal Thank you for the comments. However, I will keep it noted for future discussion.