Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
fix: circular reference in products FeeDetail
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed May 28, 2020
1 parent cbcf1e3 commit 571e29b
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/sections/products.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import {
array,
boolean,
Codec,
exactly,
GetInterface,
lazy,
number,
oneOf,
optional,
string,
unknown,
} from 'purify-ts'

import { ParsingError } from '../error'
Expand Down Expand Up @@ -42,21 +41,17 @@ 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({
PointsNumber: number,
PointsMonetaryValue: MoneyType,
})

interface Points {
PointsNumber: number
PointsMonetaryValue: MoneyType
}

type Points = GetInterface<typeof Points>
interface PriceToEstimateFees {
ListingPrice: MoneyType
Shipping?: MoneyType
Expand Down Expand Up @@ -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<FeeDetail> = 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({
Expand Down

0 comments on commit 571e29b

Please sign in to comment.