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

Commit

Permalink
feat: made getPackageTrackingDetails
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jul 21, 2020
1 parent ff337c5 commit 79f2b36
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 0 deletions.
117 changes: 117 additions & 0 deletions src/sections/fulfillment-outbound-shipment/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,120 @@ export const ListAllFulfillmentOrdersByNextTokenResponse = Codec.interface({
ListAllFulfillmentOrdersByNextTokenResult: ListAllFulfillmentOrders,
}),
})

const TrackingAddress = Codec.interface({
City: string,
State: string,
Country: string,
})

enum CurrentStatusEnum {
'IN_TRANSIT',
'DELIVERED',
'RETURNING',
'RETURNED',
'UNDELIVERABLE',
'DELAYED',
'AVAILABLE_FOR_PICKUP',
'CUSTOMER_ACTION',
}

const CurrentStatus = enumeration(CurrentStatusEnum)

enum EventCodeEnum {
'EVENT_101',
'EVENT_102',
'EVENT_201',
'EVENT_202',
'EVENT_203',
'EVENT_204',
'EVENT_205',
'EVENT_206',
'EVENT_301',
'EVENT_302',
'EVENT_304',
'EVENT_306',
'EVENT_307',
'EVENT_308',
'EVENT_309',
'EVENT_401',
'EVENT_402',
'EVENT_403',
'EVENT_404',
'EVENT_405',
'EVENT_406',
'EVENT_407',
'EVENT_408',
'EVENT_409',
'EVENT_411',
'EVENT_412',
'EVENT_413',
'EVENT_414',
'EVENT_415',
'EVENT_416',
'EVENT_417',
'EVENT_418',
'EVENT_419',
}

const EventCode = enumeration(EventCodeEnum)

const TrackingEvent = Codec.interface({
EventDate: mwsDate,
EventAddress: TrackingAddress,
EventCode,
})

enum AdditionalLocationInfoEnum {
'AS_INSTRUCTED',
'CARPORT',
'CUSTOMER_PICKUP',
'DECK',
'DOOR_PERSON',
'FRONT_DESK',
'FRONT_DOOR',
'GARAGE',
'GUARD',
'MAIL_ROOM',
'MAIL_SLOT',
'MAILBOX',
'MC_BOY',
'MC_GIRL',
'MC_MAN',
'MC_WOMAN',
'NEIGHBOR',
'OFFICE',
'OUTBUILDING',
'PATIO',
'PORCH',
'REAR_DOOR',
'RECEPTIONIST',
'RECEIVER',
'SECURE_LOCATION',
'SIDE_DOOR',
}

const AdditionalLocationInfo = enumeration(AdditionalLocationInfoEnum)

const GetPackageTrackingDetails = Codec.interface({
PackageNumber: number,
TrackingNumber: ensureString,
CarrierCode: string,
CarrierPhoneNumber: ensureString,
CarrierURL: string,
ShipDate: mwsDate,
ShipToAddress: TrackingAddress,
CurrentStatus,
SignedForBy: string,
EstimatedArrivalDate: mwsDate,
TrackingEvents: optional(ensureArray('member', TrackingEvent)),
AdditionalLocationInfo: optional(AdditionalLocationInfo),
})

export type GetPackageTrackingDetails = GetInterface<typeof GetPackageTrackingDetails>

export const GetPackageTrackingDetailsResponse = Codec.interface({
GetPackageTrackingDetailsResponse: Codec.interface({
GetPackageTrackingDetailsResult: GetPackageTrackingDetails,
}),
})
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
GetFulfillmentOrderResponse,
GetFulfillmentPreview,
GetFulfillmentPreviewResponse,
GetPackageTrackingDetails,
GetPackageTrackingDetailsResponse,
ListAllFulfillmentOrders,
ListAllFulfillmentOrdersByNextTokenResponse,
ListAllFulfillmentOrdersResponse,
Expand All @@ -20,6 +22,7 @@ import {
CreateFulfillmentOrderParameters,
GetFulfillmentOrderParameters,
GetFulfillmentPreviewParameters,
GetPackageTrackingDetailsParameters,
ListAllFulfillmentOrdersParameters,
UpdateFulfillmentOrderParameters,
} from './type'
Expand All @@ -29,6 +32,26 @@ const FOS_API_VERSION = '2010-10-01'
export class FulfillmentOutboundShipment {
constructor(private httpClient: HttpClient) {}

async getPackageTrackingDetails(
parameters: GetPackageTrackingDetailsParameters,
): Promise<[GetPackageTrackingDetails, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.FulfillmentOutboundShipment,
version: FOS_API_VERSION,
action: 'GetPackageTrackingDetails',
parameters: {
PackageNumber: parameters.PackageNumber,
},
})

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

async listAllFulfillmentOrdersByNextToken(
nextToken: NextToken<'ListAllFulfillmentOrders'>,
): Promise<[ListAllFulfillmentOrders, RequestMeta]> {
Expand Down
4 changes: 4 additions & 0 deletions src/sections/fulfillment-outbound-shipment/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,7 @@ export interface ListAllFulfillmentOrdersParameters {
export interface GetFulfillmentOrderParameters {
SellerFulfillmentOrderId: string
}

export interface GetPackageTrackingDetailsParameters {
PackageNumber: number
}
49 changes: 49 additions & 0 deletions test/unit/__snapshots__/fulfillment-outbound-shipment.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,55 @@ Array [
]
`;

exports[`fulfillmentOutboundShipment getPackageTrackingDetails returns package tracking details if succesful 1`] = `
Array [
Object {
"AdditionalLocationInfo": "FRONT_DESK",
"CarrierCode": "UPS",
"CarrierPhoneNumber": "206-000-0000",
"CarrierURL": "http://www.ups.com/",
"CurrentStatus": "DELIVERED",
"EstimatedArrivalDate": 2012-03-09T10:00:00.000Z,
"PackageNumber": 42343,
"ShipDate": 2012-03-09T10:27:10.000Z,
"ShipToAddress": Object {
"City": "Seattle",
"Country": "US",
"State": "WA",
},
"SignedForBy": "John",
"TrackingEvents": Array [
Object {
"EventAddress": Object {
"City": "Reno",
"Country": "US",
"State": "NV",
},
"EventCode": "EVENT_202",
"EventDate": 2012-03-09T08:48:53.000Z,
},
Object {
"EventAddress": Object {
"City": "Seattle",
"Country": "US",
"State": "WA",
},
"EventCode": "EVENT_301",
"EventDate": 2012-03-10T10:27:10.000Z,
},
],
"TrackingNumber": "3A18351E0390447173",
},
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": 2020-04-06T10:22:23.582Z,
"requestId": "0",
"timestamp": 2020-05-06T09:22:23.582Z,
},
]
`;

exports[`fulfillmentOutboundShipment getServiceStatus returns a parsed model when the status response is valid 1`] = `
Array [
Object {
Expand Down

0 comments on commit 79f2b36

Please sign in to comment.