From cbc567aa9070377c8e30b8ed2096c10baf3671ef Mon Sep 17 00:00:00 2001 From: EJ Mercado Date: Mon, 25 May 2020 19:58:10 +0800 Subject: [PATCH] fix: fix codec to use ensure array --- src/sections/products.ts | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/sections/products.ts b/src/sections/products.ts index 0b1ead52..96ad64e5 100644 --- a/src/sections/products.ts +++ b/src/sections/products.ts @@ -1,5 +1,4 @@ import { - array, boolean, Codec, exactly, @@ -199,21 +198,16 @@ const MatchingProductForId = Codec.interface({ Products: ensureArray('Product', Product), }) -// GetMatchingProductForId is different than other APIs, -// The example on MWS points to it possibly being an array structured this way -const GetMatchingProductForIdResult = oneOf([ +const GetMatchingProductForIdResponse = ensureArray( + 'GetMatchingProductForIdResult', MatchingProductForId, - array(MatchingProductForId), - string, -]) +) -const GetMatchingProductForIdResponse = Codec.interface({ - GetMatchingProductForIdResponse: Codec.interface({ - GetMatchingProductForIdResult, - }), +const GetMatchingProductForIdResponseCodec = Codec.interface({ + GetMatchingProductForIdResponse, }) -type GetMatchingProductForIdResult = GetInterface +type GetMatchingProductForIdResponse = GetInterface export class Products { constructor(private httpClient: HttpClient) {} @@ -281,7 +275,7 @@ export class Products { async getMatchingProductForId( parameters: GetMatchingProductForIdParameters, - ): Promise<[GetMatchingProductForIdResult, RequestMeta]> { + ): Promise<[GetMatchingProductForIdResponse, RequestMeta]> { const [response, meta] = await this.httpClient.request('POST', { resource: Resource.Products, version: PRODUCTS_API_VERSION, @@ -289,8 +283,8 @@ export class Products { parameters, }) - return GetMatchingProductForIdResponse.decode(response).caseOf({ - Right: (x) => [x.GetMatchingProductForIdResponse.GetMatchingProductForIdResult, meta], + return GetMatchingProductForIdResponseCodec.decode(response).caseOf({ + Right: (x) => [x.GetMatchingProductForIdResponse, meta], Left: (error) => { throw new ParsingError(error) },