ScaleLeap / amazon-mws-api-sdk

A fully typed TypeScript and Node.js Amazon MWS API Unofficial SDK
https://npm.im/@scaleleap/amazon-mws-api-sdk
MIT License
20 stars 12 forks source link

[Orders] error when parsing data #365

Closed Roman991 closed 3 years ago

Roman991 commented 3 years ago

seems there's some problems when parsing orders json (or xml?).

error

ERRORE ParsingError: Problem with the value of property `ListOrdersResponse`: Problem with the value of property `ListOrdersResult`: Problem with the value of property `Orders`: Problem with the value at index 0: Problem with the value of property `ShippingAddress`: One of the following problems occured: (0) Problem with the value of property `Phone`: One of the following problems occured: (0) Expected a string, but received a number with value 333333333333, (1) Expected 
an undefined, but received a number with value 333333333333, (1) Expected an undefined, but received an object with value {"City":"string","PostalCode":11111,"isAddressSharingConfidential":false,"StateOrRegion":"AA","Phone":333333333333,"CountryCode":"IT","Name":"string","AddressLine1":"string","AddressLine2":"string"}
    at Object.Left (D:\QdL\qdl\mws_service\node_modules\mws\lib\sections\orders.js:264:23)
    at Left.caseOf (D:\QdL\qdl\mws_service\node_modules\purify-ts\Either.js:267:58)
    at Orders.listOrders (D:\QdL\qdl\mws_service\node_modules\mws\lib\sections\orders.js:261:52)

\mws\lib\sections\orders.js:261:52)

    async listOrders(parameters) {
        const [response, meta] = await this.httpClient.request('POST', {
            resource: http_1.Resource.Orders,
            version: ORDERS_API_VERSION,
            action: 'ListOrders',
            parameters: canonicalizeParameters(parameters),
        });
        console.log(JSON.stringify(response))

        return ListOrdersResponse.decode(response).caseOf({
            Right: (x) => [x.ListOrdersResponse.ListOrdersResult, meta],
            Left: (error) => {
                throw new error_1.ParsingError(error);      //  <<<<<<<<<<< ERROR IS THROWED HERE
            },
        });
    }

json.stringify

......
{
"ShippingAddress":{
"City":"string",
"PostalCode":11111,           // <<<<<<<<<< number here
"isAddressSharingConfidential":false,
"StateOrRegion":"string",
"Phone":3333333333,   // <<<<< number here
"CountryCode":"string"
,"Name":"string",
"AddressLine1":"string",
"AddressLine2":"string"
}
.....

the httpCliente returns the object with those 2 fields as numbers, later I'll check also the http class

moltar commented 3 years ago

Hi Roman, which version of the package are you using?

Roman991 commented 3 years ago

Oh, Hi Roman! :) I just installed it "version": "1.9.47"

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 1.9.48 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

Roman991 commented 3 years ago

thanks, it worked. But all fields under ShippingAddress should be fixed as strings. Those fields are filled by customers, and they somethimes know to be very creative:

{
City: "Italy",
AddressLine1: 333333333,
AddressLine2: "41",
AdrressLine3: "kebab st",
PostalCode: "Rome"
}

That's why parsing by content on that fields should be off XD

https://docs.developer.amazonservices.com/en_US/orders-2013-09-01/Orders_Datatypes.html#Address

ERRORE ParsingError: Problem with the value of property `ListOrdersResponse` : 
Problem with the value of property `ListOrdersResult`: 
Problem with the value of property `Orders`: 
Problem with the value at index 7: 
Problem with the value of property `ShippingAddress`: 
One of the following problems occured: 
(0) Problem with the value of property `AddressLine2`: 
One of the following problems occured: 
(0) Expected a string, but received a number with value 36, 
(1) Expected an undefined, but received a number with value 36, ...