From 571e29b8922842fa4f0bec09ddc9714325c80bb4 Mon Sep 17 00:00:00 2001 From: EJ Mercado Date: Fri, 22 May 2020 08:36:37 +0800 Subject: [PATCH] fix: circular reference in products FeeDetail --- src/sections/products.ts | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/sections/products.ts b/src/sections/products.ts index bd2576d8..7ee84908 100644 --- a/src/sections/products.ts +++ b/src/sections/products.ts @@ -1,14 +1,13 @@ import { - array, boolean, Codec, exactly, GetInterface, + lazy, number, oneOf, optional, string, - unknown, } from 'purify-ts' import { ParsingError } from '../error' @@ -42,9 +41,9 @@ const MoneyType = Codec.interface({ CurrencyCode: oneOf(Object.values(CurrencyCodeEnum).map((x) => exactly(x))), }) -interface MoneyType { - Amount?: number - CurrencyCode?: CurrencyCode +type MoneyType = { + Amount: number | undefined + CurrencyCode: CurrencyCodeEnum } const Points = Codec.interface({ @@ -52,11 +51,7 @@ const Points = Codec.interface({ PointsMonetaryValue: MoneyType, }) -interface Points { - PointsNumber: number - PointsMonetaryValue: MoneyType -} - +type Points = GetInterface interface PriceToEstimateFees { ListingPrice: MoneyType Shipping?: MoneyType @@ -103,14 +98,27 @@ const FeesEstimateIdentifier = Codec.interface({ IsAmazonFulfilled: boolean, }) -const FeeDetail = Codec.interface({ +interface FeeDetail { + FeePromotion: MoneyType | undefined + TaxAmount: MoneyType | undefined + FinalFee: MoneyType + FeeType: string + FeeAmount: MoneyType + IncludedFeeDetailList: FeeDetail[] | undefined +} + +const FeeDetail: Codec = Codec.interface({ FeeType: string, FeeAmount: MoneyType, FeePromotion: optional(MoneyType), TaxAmount: optional(MoneyType), FinalFee: MoneyType, - IncludedFeeDetailList: optional(array(unknown)), // Unsure how to handle this - // IncludedFeeDetailList: optional(ensureArray('IncludedFeeDetail', FeeDetail)) // Need to think about how to get around this + IncludedFeeDetailList: optional( + ensureArray( + 'IncludedFeeDetail', + lazy(() => FeeDetail), + ), + ), }) const FeesEstimate = Codec.interface({