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

Commit

Permalink
feat: made listInboundShipments
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jul 15, 2020
1 parent 2f5e150 commit 71c366d
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 2 deletions.
61 changes: 60 additions & 1 deletion src/sections/fulfillment-inbound-shipment/codec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { boolean, Codec, enumeration, GetInterface, number, optional, string } from 'purify-ts'

import { ensureArray, ensureString, mwsDate } from '../../parsing'
import { ensureArray, ensureString, mwsDate, nextToken as nextTokenCodec } from '../../parsing'
import { DimensionsUnitEnum } from '../merchant-fulfillment/codec'
import {
CreateInboundShipmentParameters,
Expand Down Expand Up @@ -490,3 +490,62 @@ export const GetBillOfLadingResponse = Codec.interface({
GetBillOfLadingResult: GetBillOfLading,
}),
})

const FIBAddress = Codec.interface({
Name: string,
AddressLine1: string,
AddressLine2: optional(string),
City: string,
DistrictOrCounty: optional(string),
StateOrProvinceCode: optional(string),
CountryCode: string,
PostalCode: optional(string),
})

enum LabelPrepTypeEnum {
'NO_LABEL',
'SELLER_LABEL',
'AMAZON_LABEL',
}

const LabelPrepType = enumeration(LabelPrepTypeEnum)

enum ShipmentStatusEnum {
'WORKING',
'SHIPPED',
'IN_TRANSIT',
'DELIVERED',
'CHECKED_IN',
'RECEIVING',
'CLOSED',
'CANCELLED',
'DELETED',
'ERROR',
}

const ShipmentStatus = enumeration(ShipmentStatusEnum)

const InboundShipmentInfo = Codec.interface({
ShipmentId: optional(ensureString),
ShipmentName: optional(string),
ShipFromAddress: FIBAddress,
DestinationFulfillmentCenterId: optional(ensureString),
LabelPrepType: optional(LabelPrepType),
ShipmentStatus: optional(ShipmentStatus),
AreCasesRequired: optional(boolean),
ConfirmedNeedByDate: optional(string),
BoxContentsSource: optional(string),
EstimatedBoxContentsFeeDetails: optional(BoxContentsFeeDetails),
})

const ListInboundShipments = Codec.interface({
NextToken: optional(nextTokenCodec('ListInboundShipments')),
ShipmentData: ensureArray('member', InboundShipmentInfo),
})

export type ListInboundShipments = GetInterface<typeof ListInboundShipments>
export const ListInboundShipmentsResponse = Codec.interface({
ListInboundShipmentsResponse: Codec.interface({
ListInboundShipmentsResult: ListInboundShipments,
}),
})
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import {
GetTransportContentResponse,
GetUniquePackageLabels,
GetUniquePackageLabelsResponse,
ListInboundShipments,
ListInboundShipmentsResponse,
PutTransportContent,
PutTransportContentResponse,
UpdateInboundShipment,
Expand Down Expand Up @@ -59,6 +61,7 @@ import {
GetPrepInstructionsForSKUParameters,
GetTransportContentParameters,
GetUniquePackageLabelsParameters,
ListInboundShipmentsParameters,
PutTransportContentParameters,
VoidTransportRequestParameters,
} from './type'
Expand All @@ -68,6 +71,29 @@ const FULFILLMENT_INBOUND_SHIPMENT_API_VERSION = '2010-10-01'
export class FulfillmentInboundShipment {
constructor(private httpClient: HttpClient) {}

async listInboundShipments(
parameters: ListInboundShipmentsParameters,
): Promise<[ListInboundShipments, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.FulfillmentInboundShipment,
version: FULFILLMENT_INBOUND_SHIPMENT_API_VERSION,
action: 'ListInboundShipments',
parameters: {
'ShipmentStatusList.member': parameters.ShipmentStatusList,
'ShipmentIdList.member': parameters.ShipmentIdList,
LastUpdatedAfter: parameters.LastUpdatedAfter?.toISOString(),
LastUpdatedBefore: parameters.LastUpdatedBefore?.toISOString(),
},
})

return ListInboundShipmentsResponse.decode(response).caseOf({
Right: (x) => [x.ListInboundShipmentsResponse.ListInboundShipmentsResult, meta],
Left: (error) => {
throw new ParsingError(error)
},
})
}

async getBillOfLading(
parameters: GetBillOfLadingParameters,
): Promise<[GetBillOfLading, RequestMeta]> {
Expand Down Expand Up @@ -108,7 +134,7 @@ export class FulfillmentInboundShipment {
throw new ParsingError(error)
},
})
}
}

async getUniquePackageLabels(
parameters: GetUniquePackageLabelsParameters,
Expand Down
7 changes: 7 additions & 0 deletions src/sections/fulfillment-inbound-shipment/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,10 @@ export interface GetPalletLabelsParameters {
}

export type GetBillOfLadingParameters = SingleShipmentIdParameters

export interface ListInboundShipmentsParameters {
ShipmentStatusList?: string[]
ShipmentIdList?: string[]
LastUpdatedAfter?: Date
LastUpdatedBefore?: Date
}
87 changes: 87 additions & 0 deletions test/unit/__snapshots__/fulfillment-inbound-shipment.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,93 @@ Array [
]
`;

exports[`fulfillmentInboundShipment listInboundShipments returns shipment data if succesful 1`] = `
Array [
Object {
"ShipmentData": Array [
Object {
"DestinationFulfillmentCenterId": "YYZ1",
"LabelPrepType": "NO_LABEL",
"ShipFromAddress": Object {
"AddressLine1": "Address Line 1",
"City": "Vancouver",
"CountryCode": "CA",
"Name": "jsowprni Devo CA20",
"PostalCode": "V5V 1A1",
"StateOrProvinceCode": "BC",
},
"ShipmentId": "FBAN4QNH",
"ShipmentName": "FBA (8/27/12 1:55 PM)",
"ShipmentStatus": "WORKING",
},
Object {
"BoxContentsSource": "NONE",
"DestinationFulfillmentCenterId": "RIC2",
"LabelPrepType": "NO_LABEL",
"ShipFromAddress": Object {
"AddressLine1": "Address 1",
"City": "Vancouver",
"CountryCode": "CA",
"Name": "Janani Arvind FBA QA",
"PostalCode": "V5V 1A1",
"StateOrProvinceCode": "BC",
},
"ShipmentId": "FBA1123",
"ShipmentName": "Test MWS CA Shipment 1",
"ShipmentStatus": "WORKING",
},
],
},
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": 2020-04-06T10:22:23.582Z,
"requestId": "0",
"timestamp": 2020-05-06T09:22:23.582Z,
},
]
`;

exports[`fulfillmentInboundShipment listInboundShipments returns the correct structure succesfully 1`] = `
Array [
Object {
"NextToken": NextToken {
"action": "ListInboundShipments",
"token": "String",
},
"ShipmentData": Array [
Object {
"AreCasesRequired": true,
"BoxContentsSource": "String",
"ConfirmedNeedByDate": "String",
"DestinationFulfillmentCenterId": "String",
"LabelPrepType": "String",
"ShipFromAddress": Object {
"AddressLine1": "String",
"AddressLine2": "String",
"City": "String",
"CountryCode": "String",
"DistrictOrCounty": "String",
"Name": "String",
"PostalCode": "String",
"StateOrProvinceCode": "String",
},
"ShipmentId": "String",
"ShipmentName": "String",
"ShipmentStatus": "String",
},
],
},
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": 2020-04-06T10:22:23.582Z,
"requestId": "0",
"timestamp": 2020-05-06T09:22:23.582Z,
},
]
`;

exports[`fulfillmentInboundShipment putTransportContent returns tranport result if succesful 1`] = `
Array [
Object {
Expand Down

0 comments on commit 71c366d

Please sign in to comment.