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

Commit

Permalink
feat: init getTransportContent
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jul 13, 2020
1 parent 99b1dbe commit 239739e
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/sections/fulfillment-inbound-shipment/codec.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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<typeof GetTransportContent>

export const GetTransportContentResponse = Codec.interface({
GetTransportContentResponse: Codec.interface({
GetTransportContentResult: GetTransportContent,
}),
})
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
GetPrepInstructionsForASINResponse,
GetPrepInstructionsForSKU,
GetPrepInstructionsForSKUResponse,
GetTransportContent,
GetTransportContentResponse,
PutTransportContent,
PutTransportContentResponse,
UpdateInboundShipment,
Expand All @@ -39,6 +41,7 @@ import {
GetPreorderInfoParameters,
GetPrepInstructionsForASINParameters,
GetPrepInstructionsForSKUParameters,
GetTransportContentParameters,
PutTransportContentParameters,
} from './type'

Expand All @@ -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]> {
Expand Down
4 changes: 4 additions & 0 deletions src/sections/fulfillment-inbound-shipment/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,7 @@ export const canonicalizePutTransportContentParameters = (
export interface EstimateTransportRequestParameters {
ShipmentId: string
}

export interface GetTransportContentParameters {
ShipmentId: string
}
36 changes: 36 additions & 0 deletions test/unit/__snapshots__/fulfillment-inbound-shipment.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 239739e

Please sign in to comment.