diff --git a/src/sections/fulfillment-inbound-shipment/codec.ts b/src/sections/fulfillment-inbound-shipment/codec.ts index c1a27f02..bf408ef5 100644 --- a/src/sections/fulfillment-inbound-shipment/codec.ts +++ b/src/sections/fulfillment-inbound-shipment/codec.ts @@ -1,4 +1,4 @@ -import { boolean, Codec, enumeration, GetInterface, number, optional, string } from 'purify-ts' +import { boolean, Codec, enumeration, GetInterface, number, optional, string, unknown } from 'purify-ts' import { ensureArray, ensureString } from '../../parsing' import { CreateInboundShipmentParameters, PrepInstructionEnum, PrepOwnerEnum } from './type' @@ -280,3 +280,32 @@ export const EstimateTransportRequestResponse = Codec.interface({ EstimateTransportRequestResult: EstimateTransportRequest, }), }) + +const TransportHeader = Codec.interface({ + SellerId: string, + ShipmentId: ensureString, + IsPartnered: boolean, + ShipmentType: string, +}) + +// const TransportDetails = Codec.interface({ + +// }) + +const TransportContent = Codec.interface({ + TransportHeader, + TransportDetails: unknown, + TransportResult: unknown, +}) + +const GetTransportContent = Codec.interface({ + TransportContent, +}) + +export type GetTransportContent = GetInterface + +export const GetTransportContentResponse = Codec.interface({ + GetTransportContentResponse: Codec.interface({ + GetTransportContentResult: GetTransportContent, + }), +}) diff --git a/src/sections/fulfillment-inbound-shipment/fulfillment-inbound-shipment.ts b/src/sections/fulfillment-inbound-shipment/fulfillment-inbound-shipment.ts index e9de279f..6d49305b 100644 --- a/src/sections/fulfillment-inbound-shipment/fulfillment-inbound-shipment.ts +++ b/src/sections/fulfillment-inbound-shipment/fulfillment-inbound-shipment.ts @@ -20,6 +20,8 @@ import { GetPrepInstructionsForASINResponse, GetPrepInstructionsForSKU, GetPrepInstructionsForSKUResponse, + GetTransportContent, + GetTransportContentResponse, PutTransportContent, PutTransportContentResponse, UpdateInboundShipment, @@ -39,6 +41,7 @@ import { GetPreorderInfoParameters, GetPrepInstructionsForASINParameters, GetPrepInstructionsForSKUParameters, + GetTransportContentParameters, PutTransportContentParameters, } from './type' @@ -47,6 +50,26 @@ const FULFILLMENT_INBOUND_SHIPMENT_API_VERSION = '2010-10-01' export class FulfillmentInboundShipment { constructor(private httpClient: HttpClient) {} + async getTransportContent( + parameters: GetTransportContentParameters, + ): Promise<[GetTransportContent, RequestMeta]> { + const [response, meta] = await this.httpClient.request('POST', { + resource: Resource.FulfillmentInboundShipment, + version: FULFILLMENT_INBOUND_SHIPMENT_API_VERSION, + action: 'GetTransportContent', + parameters: { + ShipmentId: parameters.ShipmentId, + }, + }) + + return GetTransportContentResponse.decode(response).caseOf({ + Right: (x) => [x.GetTransportContentResponse.GetTransportContentResult, meta], + Left: (error) => { + throw new ParsingError(error) + }, + }) + } + async estimateTransportRequest( parameters: EstimateTransportRequestParameters, ): Promise<[EstimateTransportRequest, RequestMeta]> { diff --git a/src/sections/fulfillment-inbound-shipment/type.ts b/src/sections/fulfillment-inbound-shipment/type.ts index 661b46a0..469e6645 100644 --- a/src/sections/fulfillment-inbound-shipment/type.ts +++ b/src/sections/fulfillment-inbound-shipment/type.ts @@ -351,3 +351,7 @@ export const canonicalizePutTransportContentParameters = ( export interface EstimateTransportRequestParameters { ShipmentId: string } + +export interface GetTransportContentParameters { + ShipmentId: string +} diff --git a/test/unit/__snapshots__/fulfillment-inbound-shipment.test.ts.snap b/test/unit/__snapshots__/fulfillment-inbound-shipment.test.ts.snap index b56ea422..3e96fcac 100644 --- a/test/unit/__snapshots__/fulfillment-inbound-shipment.test.ts.snap +++ b/test/unit/__snapshots__/fulfillment-inbound-shipment.test.ts.snap @@ -268,6 +268,42 @@ Array [ ] `; +exports[`fulfillmentInboundShipment getTransportContent returns the transport content if succesful 1`] = ` +Array [ + Object { + "TransportContent": Object { + "TransportDetails": Object { + "NonPartneredSmallParcelData": Object { + "PackageList": Object { + "member": Object { + "CarrierName": "UNITED PARCEL SERVICE INC", + "PackageStatus": "SHIPPED", + "TrackingId": "1Z6Y68W00342402864", + }, + }, + }, + }, + "TransportHeader": Object { + "IsPartnered": false, + "SellerId": "A135KKEKWF1J56", + "ShipmentId": "FBAQ6QBP", + "ShipmentType": "SP", + }, + "TransportResult": Object { + "TransportStatus": "WORKING", + }, + }, + }, + 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 {