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

Commit

Permalink
fix: fix issues that popped up due to cleanParameters change
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jul 3, 2020
1 parent ec895a2 commit 5fe2987
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 12 deletions.
7 changes: 3 additions & 4 deletions src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ export type HttpMethod = 'GET' | 'POST'
export type ParameterTypes =
| string
| number
| (number | string)[]
| (number | string | object)[]
| boolean
| { [key: string]: ParameterTypes }
| { [key: string]: ParameterTypes }[]
| undefined

export type Parameters = Record<string, ParameterTypes>
Expand Down Expand Up @@ -205,7 +204,7 @@ export const cleanParameters = (
.filter(([, parameter]) => parameter !== undefined)

// Loop through each key
.reduce((result, [key, parameter]) => {
.reduce((_, [key, parameter]) => {
const trueKey = outerKey ? `${outerKey}.${key}` : key
/**
* If parameter is type string, number, boolean assign it to result
Expand All @@ -220,7 +219,7 @@ export const cleanParameters = (
/**
* If parameter is type array reduce it to dotnotation
*/
parameter.forEach((parameterChild: ParameterTypes, index: number) => {
parameter.forEach((parameterChild: object | string | number | boolean, index: number) => {
if (
typeof parameterChild === 'string' ||
!Number.isNaN(Number(parameterChild)) ||
Expand Down
78 changes: 72 additions & 6 deletions src/sections/merchant-fulfillment/type.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
interface CanonicalizedAddtionalSellerInput
extends Omit<AdditionalSellerInput, 'ValueAsTimestamp'> {
interface CanonicalizedAddtionalSellerInput {
ValueAsString?: string
ValueAsBoolean?: boolean
ValueAsInteger?: number
ValueAsAddress?: Address
ValueAsWeight?: Weight
ValueAsDimension?: PackageDimensions
ValueAsCurrency?: CurrencyAmount
ValueAsTimestamp?: string
DataType: SellerInputDataType
[key: string]:
| string
| boolean
| number
| Address
| Weight
| PackageDimensions
| CurrencyAmount
| string
| undefined
}
interface CanonicalizedSellerInputs {
AdditionalInputFieldName: string
AdditionalSellerInput: CanonicalizedAddtionalSellerInput
[key: string]: string | CanonicalizedAddtionalSellerInput
}

export const canonicalizeAdditionalSellerInputs = (
Expand Down Expand Up @@ -41,10 +59,42 @@ export const canonicalizeAdditionalSellerInputs = (
})
}

interface CanonicalizedItem {
OrderItemId: string
Quantity: number
ItemWeight?: Weight
ItemDescription?: string
TransparencyCodeList?: string[]
ItemLevelSellerInputsList?: CanonicalizedSellerInputs[]
[key: string]: string | number | Weight | string[] | CanonicalizedSellerInputs[] | undefined
}

interface CanonicalizedShipmentRequestDetails {
AmazonOrderId: string
SellerOrderId?: string
'ItemList.Item': CanonicalizedItem[]
ShipFromAddress: Address
PackageDimensions: PackageDimensions
Weight: Weight
MustArriveByDate?: string
ShipDate?: string
ShippingServiceOptions: ShippingServiceOptions
LabelCustomization?: LabelCustomization
[key: string]:
| string
| CanonicalizedItem[]
| Address
| PackageDimensions
| Weight
| ShippingServiceOptions
| LabelCustomization
| undefined
}

// @todo unit test both of these
export const canonicalizeShipmentRequestDetails = (
shipmentRequestDetails: ShipmentRequestDetails,
) => {
): CanonicalizedShipmentRequestDetails => {
const {
AmazonOrderId,
SellerOrderId,
Expand Down Expand Up @@ -221,7 +271,6 @@ export interface Item {
ItemDescription?: string
TransparencyCodeList?: string[]
ItemLevelSellerInputsList?: AdditionalSellerInputs[]
[key: string]: string | Weight | AdditionalSellerInputs[] | number | undefined | string[]
}

export type DeliveryExperience =
Expand Down Expand Up @@ -307,8 +356,25 @@ export interface CreateShipmentParameters {
ShipmentLevelSellerInputsList?: AdditionalSellerInputs[]
}

// @todo unit test
export const canonicalizeCreateShipmentParameters = (parameters: CreateShipmentParameters) => {
interface CanonicalizedCreateShipmentParameters {
ShipmentRequestDetails: CanonicalizedShipmentRequestDetails
ShippingServiceId: string
ShippingServiceOfferId?: string
HazmatType?: HazmatType
LabelFormatOption?: LabelFormatOption
'ShipmentLevelSellerInputsList.member'?: CanonicalizedSellerInputs[]
[key: string]:
| CanonicalizedShipmentRequestDetails
| string
| HazmatType
| LabelFormatOption
| CanonicalizedSellerInputs[]
| undefined
}

export const canonicalizeCreateShipmentParameters = (
parameters: CreateShipmentParameters,
): CanonicalizedCreateShipmentParameters => {
const {
ShipmentRequestDetails,
ShippingServiceId,
Expand Down
4 changes: 3 additions & 1 deletion src/sections/products/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ export class Products {
resource: Resource.Products,
version: PRODUCTS_API_VERSION,
action: 'GetMyFeesEstimate',
parameters,
parameters: {
'FeesEstimateRequestList.FeesEstimateRequest': parameters.FeesEstimateRequestList,
},
})

return GetMyFeesEstimateResponse.decode(response).caseOf({
Expand Down
1 change: 0 additions & 1 deletion src/sections/products/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export interface FeesEstimateRequest {

export interface GetMyFeesEstimateParameters {
FeesEstimateRequestList: FeesEstimateRequest[]
[key: string]: FeesEstimateRequest[]
}

export interface ListMatchingProductsRequestParameters {
Expand Down

0 comments on commit 5fe2987

Please sign in to comment.