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

Commit

Permalink
fix: all ASINs are strings
Browse files Browse the repository at this point in the history
  • Loading branch information
moltar committed Dec 23, 2020
1 parent 26958d1 commit a30f2bd
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 38 deletions.
6 changes: 6 additions & 0 deletions src/parsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,9 @@ export const nextToken = <T extends string>(action: T) =>
* XML parser will parse them to a number.
*/
export const SKU = ensureString

/**
* A shorthand for all ASINs, which are always strings, but when they consist of just numbers,
* XML parser will parse them to a number.
*/
export const ASIN = ensureString
19 changes: 13 additions & 6 deletions src/sections/finances/codec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { Codec, enumeration, GetType, number, oneOf, optional, string, unknown } from 'purify-ts'

import { ensureArray, ensureString, mwsDate, nextToken as nextTokenCodec, SKU } from '../../parsing'
import {
ASIN,
ensureArray,
ensureString,
mwsDate,
nextToken as nextTokenCodec,
SKU,
} from '../../parsing'
import { CurrencyAmount } from '../codec'
import { FulfillmentChannelEnum } from '../types'

Expand Down Expand Up @@ -278,7 +285,7 @@ const ServiceFeeEvent = Codec.interface({
SellerSKU: optional(SKU),
FnSKU: optional(SKU),
FeeDesription: optional(string),
ASIN: optional(ensureString),
ASIN: optional(ASIN),
})

const DebtRecoveryItem = Codec.interface({
Expand Down Expand Up @@ -348,7 +355,7 @@ const AdjustmentItem = Codec.interface({
SellerSKU: optional(SKU),
FnSKU: optional(SKU),
ProductDescription: optional(string),
ASIN: optional(ensureString),
ASIN: optional(ASIN),
})

const AdjustmentEvent = Codec.interface({
Expand Down Expand Up @@ -385,7 +392,7 @@ const SAFETReimbursementEvent = Codec.interface({
const SellerReviewEnrollmentPaymentEvent = Codec.interface({
PostedDate: optional(mwsDate),
EnrollmentId: optional(ensureString),
ParentASIN: optional(ensureString),
ParentASIN: optional(ASIN),
FeeComponent: optional(FeeComponent),
ChargeComponent: optional(ChargeComponent),
TotalAmount: optional(CurrencyAmount),
Expand All @@ -400,7 +407,7 @@ const FBALiquidationEvent = Codec.interface({

const ImagingServicesFeeEvent = Codec.interface({
ImagingRequestBillingItemID: optional(ensureString),
ASIN: optional(ensureString),
ASIN: optional(ASIN),
PostedDate: optional(mwsDate),
FeeList: optional(ensureArray('FeeComponent', FeeComponent)),
})
Expand Down Expand Up @@ -441,7 +448,7 @@ const NetworkComminglingTransactionEvent = Codec.interface({
NetCoTransactionID: optional(ensureString),
SwapReason: optional(string),
TransactionType: optional(NetworkComminglingTransactionType),
ASIN: optional(ensureString),
ASIN: optional(ASIN),
MarketplaceId: optional(string),
TaxExclusiveAmount: optional(CurrencyAmount),
TaxAmount: optional(CurrencyAmount),
Expand Down
19 changes: 13 additions & 6 deletions src/sections/fulfillment-inbound-shipment/codec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { boolean, Codec, enumeration, GetType, number, optional, string } from 'purify-ts'

import { ensureArray, ensureString, mwsDate, nextToken as nextTokenCodec, SKU } from '../../parsing'
import {
ASIN,
ensureArray,
ensureString,
mwsDate,
nextToken as nextTokenCodec,
SKU,
} from '../../parsing'
import { DimensionsUnitEnum } from '../merchant-fulfillment/codec'
import {
CreateInboundShipmentParameters,
Expand All @@ -25,7 +32,7 @@ export const InboundGuidance = enumeration(InboundGuidanceEnum)

export const SKUInboundGuidance = Codec.interface({
SellerSKU: SKU,
ASIN: ensureString,
ASIN,
InboundGuidance,
GuidanceReasonList: optional(ensureArray('GuidanceReason', GuidanceReason)),
})
Expand All @@ -49,12 +56,12 @@ export const GetInboundGuidanceForSKUResponse = Codec.interface({
})

export const InvalidASIN = Codec.interface({
ASIN: ensureString,
ASIN,
ErrorReason: string,
})

export const ASINInboundGuidance = Codec.interface({
ASIN: ensureString,
ASIN,
InboundGuidance,
GuidanceReasonList: optional(ensureArray('GuidanceReason', GuidanceReason)),
})
Expand Down Expand Up @@ -205,7 +212,7 @@ export const AmazonPrepFeesDetails = Codec.interface({

export const SKUPrepInstructions = Codec.interface({
SellerSKU: SKU,
ASIN: ensureString,
ASIN,
BarcodeInstruction,
PrepGuidance,
PrepInstructionList: ensureArray('PrepInstruction', PrepInstruction),
Expand All @@ -226,7 +233,7 @@ export const GetPrepInstructionsForSKUResponse = Codec.interface({
})

export const ASINPrepInstructions = Codec.interface({
ASIN: ensureString,
ASIN,
BarcodeInstruction,
PrepGuidance,
PrepInstructionList: ensureArray('PrepInstruction', PrepInstruction),
Expand Down
11 changes: 2 additions & 9 deletions src/sections/fulfillment-inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ import { Codec, enumeration, GetType, number, optional, string } from 'purify-ts

import { ParsingError } from '../error'
import { HttpClient, RequestMeta, Resource } from '../http'
import {
ensureArray,
ensureString,
mwsDate,
NextToken,
nextToken as nextTokenCodec,
SKU,
} from '../parsing'
import { ASIN, ensureArray, mwsDate, NextToken, nextToken as nextTokenCodec, SKU } from '../parsing'
import { getServiceStatusByResource } from './shared'
import { RequireOnlyOne } from './types'

Expand Down Expand Up @@ -65,7 +58,7 @@ const InventorySupplyDetail = Codec.interface({
const InventorySupply = Codec.interface({
SellerSKU: optional(SKU),
FNSKU: SKU,
ASIN: optional(ensureString),
ASIN: optional(ASIN),
Condition: optional(enumeration(InventoryCondition)),
TotalSupplyQuantity: number,
InStockSupplyQuantity: number,
Expand Down
4 changes: 2 additions & 2 deletions src/sections/merchant-fulfillment/codec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { boolean, Codec, enumeration, GetType, number, optional, string } from 'purify-ts'

import { ensureArray, ensureString, mwsDate } from '../../parsing'
import { ASIN, ensureArray, ensureString, mwsDate } from '../../parsing'
import { PredefinedPackageDimensionsEnum } from './type'

export const TemporarilyUnavailableCarrier = Codec.interface({
Expand Down Expand Up @@ -183,7 +183,7 @@ export const AdditionalInputs = Codec.interface({
})

export const ItemLevelFields = Codec.interface({
Asin: ensureString,
Asin: ASIN,
AdditionalInputs: ensureArray('member', AdditionalInputs),
})

Expand Down
3 changes: 2 additions & 1 deletion src/sections/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { boolean, Codec, enumeration, GetType, number, optional, string } from '
import { ParsingError } from '../error'
import { HttpClient, RequestMeta, Resource } from '../http'
import {
ASIN,
ensureArray,
ensureString,
mwsDate,
Expand Down Expand Up @@ -199,7 +200,7 @@ export const ListOrderItems = Codec.interface({
OrderItems: ensureArray(
'OrderItem',
Codec.interface({
ASIN: ensureString,
ASIN,
OrderItemId: ensureString,
SellerSKU: optional(SKU),
BuyerCustomizedInfo: optional(
Expand Down
7 changes: 4 additions & 3 deletions src/sections/products/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from 'purify-ts'

import { Error } from '../../error-codec'
import { ensureArray, ensureString, mwsDate, SKU } from '../../parsing'
import { ASIN, ensureArray, ensureString, mwsDate, SKU } from '../../parsing'
import {
CurrencyCodeEnum,
FeeDetail as FeeDetailInterface,
Expand Down Expand Up @@ -45,6 +45,7 @@ export enum StatusEnum {
const Status = enumeration(StatusEnum)

export enum IdTypeEnum {
// eslint-disable-next-line no-shadow, @typescript-eslint/no-shadow
ASIN = 'ASIN',
// eslint-disable-next-line no-shadow, @typescript-eslint/no-shadow
SKU = 'SKU',
Expand Down Expand Up @@ -127,7 +128,7 @@ const AttributeSetList = AbstractObject

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

const SellerSKUIdentifier = Codec.interface({
Expand Down Expand Up @@ -369,7 +370,7 @@ const SkuIdentifier = Codec.interface({
})

const AsinIdentifier = Codec.interface({
ASIN: ensureString,
ASIN,
...Identifier,
})

Expand Down
11 changes: 2 additions & 9 deletions src/sections/recommendations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ import { Codec, enumeration, exactly, GetType, number, oneOf, optional, string }

import { ParsingError } from '../error'
import { HttpClient, RequestMeta, Resource } from '../http'
import {
ensureArray,
ensureString,
mwsDate,
NextToken,
nextToken as nextTokenCodec,
SKU,
} from '../parsing'
import { ASIN, ensureArray, mwsDate, NextToken, nextToken as nextTokenCodec, SKU } from '../parsing'
import { getServiceStatusByResource } from './shared'
import { FulfillmentChannelEnum } from './types'

Expand Down Expand Up @@ -61,7 +54,7 @@ export interface ListRecommendationsParameters {
}

const ProductIdentifier = Codec.interface({
Asin: ensureString,
Asin: ASIN,
Sku: SKU,
Upc: string,
})
Expand Down
4 changes: 2 additions & 2 deletions src/sections/shipment-invoicing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Codec, enumeration, exactly, GetType, number, optional, string, unknown

import { ParsingError } from '../error'
import { HttpClient, RequestMeta, Resource } from '../http'
import { ensureArray, ensureString, SKU } from '../parsing'
import { ASIN, ensureArray, ensureString, SKU } from '../parsing'
import { getServiceStatusByResource } from './shared'

const SHIPMENT_INVOICING_API_VERSION = '2018-09-01'
Expand Down Expand Up @@ -45,7 +45,7 @@ export const Money = Codec.interface({
})

const ShipmentItem = Codec.interface({
ASIN: ensureString,
ASIN,
SellerSKU: optional(SKU),
OrderItemId: ensureString,
Title: optional(string),
Expand Down

0 comments on commit a30f2bd

Please sign in to comment.