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

Commit

Permalink
refactor: define products attributes 4 out of 7. based on c# lib
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jul 29, 2020
1 parent 2d04484 commit da2fdd6
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 119 deletions.
71 changes: 69 additions & 2 deletions src/sections/products/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
number,
oneOf,
optional,
record,
string,
unknown,
} from 'purify-ts'
Expand Down Expand Up @@ -120,7 +119,75 @@ export const GetMyFeesEstimateResponse = Codec.interface({
}),
})

const Product = record(string, unknown)
// Amazon C# library has properties that are a type "any" they call an "abstract object"
const AbstractObject = unknown

const AttributeSetList = AbstractObject

const ASINIdentifier = Codec.interface({
MarketplaceId: string,
ASIN: ensureString,
})

const SellerSKUIdentifier = Codec.interface({
MarketplaceId: string,
SellerId: ensureString,
SellerSKU: ensureString,
})

const IdentifierType = Codec.interface({
MarketplaceASIN: optional(ASINIdentifier),
SKUIdentifier: optional(SellerSKUIdentifier),
})

const RelationshipList = AbstractObject

const PriceType = Codec.interface({
LandedPrice: optional(MoneyType),
ListingPrice: optional(MoneyType),
Shipping: optional(MoneyType),
Points: optional(PointsCodec),
})

const CompetitivePriceType = Codec.interface({
attr: Codec.interface({
condition: string,
subcondition: string,
belongsToRequester: optional(string), // @todo this is supposed to return a boolean
}),
CompetitivePriceId: ensureString,
Price: PriceType,
})

const CompetitivePriceList = ensureArray('CompetitivePrice', CompetitivePriceType)

const OfferListingCountType = Codec.interface({
attr: Codec.interface({
condition: string,
}),
text: number,
})

const NumberOfOfferListingsList = ensureArray('OfferListingCount', OfferListingCountType)

const CompetitivePricingType = Codec.interface({
CompetitivePrices: optional(CompetitivePriceList),
NumberOfOfferListings: optional(NumberOfOfferListingsList),
TradeInValue: optional(MoneyType),
})
const SalesRankList = unknown
const LowestOfferListingList = unknown
const Offers = unknown
// @todo all unknowns
const Product = Codec.interface({
Identifiers: optional(IdentifierType),
AttributeSets: optional(AttributeSetList),
Relationships: optional(RelationshipList),
CompetitivePricing: optional(CompetitivePricingType),
SalesRankings: optional(SalesRankList),
LowestOfferListings: optional(LowestOfferListingList),
Offers: optional(Offers),
})

const SingleProductInterface = Codec.interface({
Product,
Expand Down
Loading

0 comments on commit da2fdd6

Please sign in to comment.