This repository has been archived by the owner on Feb 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: made getEligibleShippingServices codecs and added more tests
- Loading branch information
1 parent
9726bf9
commit d2b577a
Showing
10 changed files
with
464 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Codec, number, optional, string } from 'purify-ts' | ||
|
||
/** | ||
* Shared codecs | ||
*/ | ||
|
||
export const CurrencyAmount = Codec.interface({ | ||
CurrencyCode: optional(string), | ||
CurrencyAmount: optional(number), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/sections/merchant-fulfillment/merchant-fulfillment.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { boolean, Codec, enumeration, GetInterface, optional, string } from 'purify-ts' | ||
|
||
import { ParsingError } from '../../error' | ||
import { HttpClient, RequestMeta, Resource } from '../../http' | ||
import { ensureArray, ensureString, mwsDate } from '../../parsing' | ||
import { CurrencyAmount } from '../codec' | ||
import { getServiceStatusByResource } from '../shared' | ||
import { | ||
canonicalizeParametersGetEligibleShippingServiceParameters, | ||
GetEligibleShippingServicesParameters, | ||
} from './type' | ||
|
||
const MERCHANT_FULFILLMENT_API_VERSION = '2015-06-01' | ||
|
||
const TemporarilyUnavailableCarrier = Codec.interface({ | ||
CarrierName: string, | ||
}) | ||
|
||
const RejectedShippingService = Codec.interface({ | ||
CarrierName: string, | ||
ShippingServiceId: string, | ||
RejectionReasonCode: string, | ||
RejectionReasonMessage: string, | ||
ShippingServiceName: string, | ||
}) | ||
|
||
enum DeliveryExperienceEnum { | ||
DeliveryConfirmationWithAdultSignature = 'DeliveryConfirmationWithAdultSignature', | ||
DeliveryConfirmationWithSignature = 'DeliveryConfirmationWithSignature', | ||
DeliveryConfirmationWithoutSignature = 'DeliveryConfirmationWithoutSignature', | ||
NoTracking = 'NoTracking', | ||
} | ||
|
||
const DeliveryExperience = enumeration(DeliveryExperienceEnum) | ||
|
||
const ShippingServiceOptions = Codec.interface({ | ||
DeliveryExperience, | ||
DeclaredValue: optional(CurrencyAmount), | ||
CarrierWillPickUp: boolean, | ||
LabelFormat: optional(string), | ||
}) | ||
|
||
const ShippingService = Codec.interface({ | ||
ShippingServiceName: string, | ||
CarrierName: string, | ||
ShippingServiceId: ensureString, | ||
ShippingServiceOfferId: ensureString, | ||
ShipDate: mwsDate, | ||
EarliestEstimatedDeliveryDate: optional(mwsDate), | ||
LatestEstimatedDeliveryDate: optional(mwsDate), | ||
Rate: CurrencyAmount, | ||
ShippingServiceOptions, | ||
AvailableLabelFormats: optional(ensureArray('LabelFormat', string)), | ||
RequiresAdditionalSellerInputs: boolean, | ||
}) | ||
|
||
const GetEligibleShippingServices = Codec.interface({ | ||
ShippingServiceList: ensureArray('ShippingService', ShippingService), | ||
RejectedShippingServiceList: ensureArray('RejectedShippingService', RejectedShippingService), | ||
TemporarilyUnavailableCarrierList: ensureArray( | ||
'TemporarilyUnavailableCarrier', | ||
TemporarilyUnavailableCarrier, | ||
), | ||
TermsAndConditionsNotAcceptedCarrierList: ensureArray( | ||
'TermsAndConditionsNotAcceptedCarrier', | ||
TemporarilyUnavailableCarrier, | ||
), | ||
}) | ||
|
||
type GetEligibleShippingServices = GetInterface<typeof GetEligibleShippingServices> | ||
|
||
const GetEligibleShippingServicesResponse = Codec.interface({ | ||
GetEligibleShippingServicesResponse: Codec.interface({ | ||
GetEligibleShippingServicesResult: GetEligibleShippingServices, | ||
}), | ||
}) | ||
|
||
export class MerchantFulfillment { | ||
constructor(private httpClient: HttpClient) {} | ||
|
||
async getEligibleShippingServices( | ||
parameters: GetEligibleShippingServicesParameters, | ||
): Promise<[GetEligibleShippingServices, RequestMeta]> { | ||
const [response, meta] = await this.httpClient.request('POST', { | ||
resource: Resource.MerchantFulfillment, | ||
version: MERCHANT_FULFILLMENT_API_VERSION, | ||
action: 'GetEligibleShippingServices', | ||
parameters: canonicalizeParametersGetEligibleShippingServiceParameters(parameters), | ||
}) | ||
|
||
return GetEligibleShippingServicesResponse.decode(response).caseOf({ | ||
Right: (x) => [x.GetEligibleShippingServicesResponse.GetEligibleShippingServicesResult, meta], | ||
Left: (error) => { | ||
throw new ParsingError(error) | ||
}, | ||
}) | ||
} | ||
|
||
async getServiceStatus() { | ||
return getServiceStatusByResource( | ||
this.httpClient, | ||
Resource.MerchantFulfillment, | ||
MERCHANT_FULFILLMENT_API_VERSION, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.