amz-tools / amazon-sp-api

Amazon Selling Partner API Client
MIT License
230 stars 119 forks source link

Incorrect inferred typing when using operation and endpoint #244

Open jakeleventhal opened 11 months ago

jakeleventhal commented 11 months ago

When making calls the API using inferred types (endpoint + operation), I am getting the wrong type for my payload variable.

const payload = await this.sellingPartner.callAPI({
  endpoint: 'finances',
  operation: 'listFinancialEventGroups',
  query: {
    FinancialEventGroupStartedAfter: startDate.toISOString()
  }
});
Screenshot 2023-10-02 at 4 53 03 PM


It seems to think that i should be destructuring payload when the value is already destructured. Below is what i see when i log payload

Screenshot 2023-10-02 at 4 53 51 PM
jakeleventhal commented 11 months ago

@amz-tools

jakeleventhal commented 10 months ago

This is still an issue on 1.0.0 and is a blocker for wanting to have any sort of type inferencing

jakeleventhal commented 9 months ago

I can fix this myself. Can @amz-tools please provide some guidance for how to fix this?

curiousElf commented 8 months ago

@jakeleventhal How did you go about fixing this? Do we need to rewrite all the nested types ourselves?

jakeleventhal commented 8 months ago

@jakeleventhal How did you go about fixing this? Do we need to rewrite all the nested types ourselves?

import { GetOrderPath, GetOrderResponse } from 'amazon-sp-api/lib/typings/operations/orders';

  async getOrder(orderId: string): Promise<GetOrderResponse['payload']> {
    try {
      const order = await this.sellingPartner.callAPI({
        operation: 'orders.getOrder',
        path: { orderId } as GetOrderPath
      });

      return order;
    } catch (err) {
      const handledError = await this.handleAPIError(err);
      throw handledError;
    }
  }

annoying, but works

jakeleventhal commented 5 months ago

@amz-tools any guidance here? Will gladly take this on.

GbalsaC commented 2 months ago

This is still an issue, it'd be great if it could be corrected as others migrate to newest version and need to make use of type checking

pradeep-gox commented 1 week ago

+1

I assume this is the following piece of code in the SellingPartner.js lib file, which causes this problem. @amz-tools IMO, I think the developers could do the transformation/processing of the response. The raw json response from the sp-api should be returned for better consistency.

image

pradeep-gox commented 1 week ago

https://github.com/amz-tools/amazon-sp-api/pull/290