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

Commit

Permalink
feat: create codec for getAdditionalSellerInputs
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jul 2, 2020
1 parent 6147301 commit c264821
Show file tree
Hide file tree
Showing 5 changed files with 383 additions and 59 deletions.
1 change: 0 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1889,7 +1889,6 @@ const [response, meta] = finances.listFinancialEvents(new NextToken('ListFinanci
| ValueAsCurrency | CurrencyAmount | [`CurrencyAmount`](#currencyamount) | No |

* Possible values for `DataType`: `'String'`, `'Boolean'`, `'Integer'`, `'Timestamp'`, `'Address'`, `'Weight'`, `'Dimension'`, `'Currency'`,
* Fill in `ValueAs[DataType]` depending on the value for `DataType`

#### CurrencyAmount
**Parameters**
Expand Down
135 changes: 129 additions & 6 deletions src/sections/merchant-fulfillment/merchant-fulfillment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { boolean, Codec, enumeration, GetInterface, optional, string, unknown } from 'purify-ts'
import { boolean, Codec, enumeration, GetInterface, number, optional, string } from 'purify-ts'

import { ParsingError } from '../../error'
import { HttpClient, RequestMeta, Resource } from '../../http'
Expand All @@ -8,6 +8,7 @@ import { getServiceStatusByResource } from '../shared'
import {
canonicalizeParametersGetEligibleShippingServiceParameters,
GetEligibleShippingServicesParameters,
PredefinedPackageDimensionsEnum,
} from './type'

const MERCHANT_FULFILLMENT_API_VERSION = '2015-06-01'
Expand Down Expand Up @@ -74,9 +75,131 @@ const GetEligibleShippingServicesResponse = Codec.interface({
GetEligibleShippingServicesResult: GetEligibleShippingServices,
}),
})
// interface GetAdditionalSellerInputsParameters {}
interface GetAdditionalSellerInputsParameters {
OrderId: string
ShippingServiceId: string
ShipFromAddress: string
[key: string]: string
}

enum DataTypeEnum {
String = 'String',
Boolean = 'Boolean',
Integer = 'Integer',
Timestamp = 'Timestamp',
Address = 'Address',
Weight = 'Weight',
Dimension = 'Dimension',
Currency = 'Currency',
STRING = 'STRING',
BOOLEAN = 'BOOLEAN',
INTEGER = 'INTEGER',
TIMESTAMP = 'TIMESTAMP',
ADDRESS = 'ADDRESS',
WEIGHT = 'WEIGHT',
DIMENSION = 'DIMENSION',
CURRENCY = 'CURRENCY',
}

const DataType = enumeration(DataTypeEnum)

const Constraints = Codec.interface({
ValidationRegEx: string,
ValidationString: string,
})

enum InputTargetEnum {
ITEM_LEVEL = 'ITEM_LEVEL',
SHIPMENT_LEVEL = 'SHIPMENT_LEVEL',
}

const InputTarget = enumeration(InputTargetEnum)

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

const Weight = Codec.interface({
Value: number,
Unit: string,
})

const PredefinedPackageDimensions = enumeration(PredefinedPackageDimensionsEnum)

enum DimensionsUnitEnum {
inches = 'inches',
centimeters = 'centimeters',
}

const DimensionsUnit = enumeration(DimensionsUnitEnum)

const GetAdditionalSellerInputs = unknown
const PackageDimensions = Codec.interface({
Length: optional(number),
Width: optional(number),
Height: optional(number),
Unit: optional(DimensionsUnit),
PredefinedPackageDimensions,
})

const StoredValue = Codec.interface({
DataType,
ValueAsString: optional(ensureString),
ValueAsBoolean: optional(boolean),
ValueAsInteger: optional(number),
ValueAsTimeStamp: optional(mwsDate),
ValueAsAddress: optional(Address),
ValueAsWeight: optional(Weight),
ValueAsDimension: optional(PackageDimensions),
ValueAsCurrency: optional(CurrencyAmount),
})

const SellerInputDefinition = Codec.interface({
IsRequired: boolean,
DataType,
Constraints: ensureArray('member', Constraints),
InputDisplayText: string,
InputTarget: optional(InputTarget),
// This is 'required' in docs, but it's not present in some examples
StoredValue: optional(StoredValue),
RestrictedSetValues: optional(ensureArray('member', string)),
})

enum AdditionalInputFieldNameEnum {
NON_DELIVERABLE_INSTRUCTIONS = 'NON_DELIVERABLE_INSTRUCTIONS',
SENDER_ADDRESS_TRANSLATED = 'SENDER_ADDRESS_TRANSLATED',
}

const AdditionalInputFieldName = enumeration(AdditionalInputFieldNameEnum)

const ShipmentLeveFields = Codec.interface({
AdditionalInputFieldName: optional(AdditionalInputFieldName),
SellerInputDefinition: optional(SellerInputDefinition),
})

const AdditionalInputs = Codec.interface({
AdditionalInputFieldName: string,
SellerInputDefinition,
})

const ItemLevelFields = Codec.interface({
Asin: string,
AdditionalInputs: ensureArray('member', AdditionalInputs),
})

const GetAdditionalSellerInputs = Codec.interface({
ShipmentLevelFields: ensureArray('member', ShipmentLeveFields),
ItemLevelFieldsList: ensureArray('member', ItemLevelFields),
})
type GetAdditionalSellerInputs = GetInterface<typeof GetAdditionalSellerInputs>

const GetAdditionalSellerInputsResponse = Codec.interface({
Expand All @@ -87,9 +210,9 @@ const GetAdditionalSellerInputsResponse = Codec.interface({
export class MerchantFulfillment {
constructor(private httpClient: HttpClient) {}

async getAddtionalSellerInputs(parameters: {}): Promise<
[GetAdditionalSellerInputs, RequestMeta]
> {
async getAddtionalSellerInputs(
parameters: GetAdditionalSellerInputsParameters,
): Promise<[GetAdditionalSellerInputs, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.MerchantFulfillment,
version: MERCHANT_FULFILLMENT_API_VERSION,
Expand Down
107 changes: 56 additions & 51 deletions src/sections/merchant-fulfillment/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,58 +36,63 @@ export interface Address {
Phone: string
[key: string]: string | undefined
}
// eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable camelcase */
export enum PredefinedPackageDimensionsEnum {
FedEx_Box_10kg = 'FedEx_Box_10kg',
FedEx_Box_25kg = 'FedEx_Box_25kg',
FedEx_Box_Extra_Large_1 = 'FedEx_Box_Extra_Large_1',
FedEx_Box_Extra_Large_2 = 'FedEx_Box_Extra_Large_2',
FedEx_Box_Large_1 = 'FedEx_Box_Large_1',
FedEx_Box_Large_2 = 'FedEx_Box_Large_2',
FedEx_Box_Medium_1 = 'FedEx_Box_Medium_1',
FedEx_Box_Medium_2 = 'FedEx_Box_Medium_2',
FedEx_Box_Small_1 = 'FedEx_Box_Small_1',
FedEx_Box_Small_2 = 'FedEx_Box_Small_2',
FedEx_Envelope = 'FedEx_Envelope',
FedEx_Padded_Pak = 'FedEx_Padded_Pak',
FedEx_Pak_2 = 'FedEx_Pak_2',
FedEx_Pak_1 = 'FedEx_Pak_1',
FedEx_Tube = 'FedEx_Tube',
FedEx_XL_Pak = 'FedEx_XL_Pak',
UPS_Box_10kg = 'UPS_Box_10kg',
UPS_Box_25kg = 'UPS_Box_25kg',
UPS_Express_Box = 'UPS_Express_Box',
UPS_Express_Box_Large = 'UPS_Express_Box_Large',
UPS_Express_Box_Medium = 'UPS_Express_Box_Medium',
UPS_Express_Box_Small = 'UPS_Express_Box_Small',
UPS_Express_Envelope = 'UPS_Express_Envelope',
UPS_Express_Hard_Pak = 'UPS_Express_Hard_Pak',
UPS_Express_Legal_Envelope = 'UPS_Express_Legal_Envelope',
UPS_Express_Pak = 'UPS_Express_Pak',
UPS_Express_Tube = 'UPS_Express_Tube',
UPS_Laboratory_Pak = 'UPS_Laboratory_Pak',
UPS_Pad_Pak = 'UPS_Pad_Pak',
UPS_Pallet = 'UPS_Pallet',
USPS_Card = 'USPS_Card',
USPS_Flat = 'USPS_Flat',
USPS_FlatRateCardboardEnvelope = 'USPS_FlatRateCardboardEnvelope',
USPS_FlatRateEnvelope = 'USPS_FlatRateEnvelope',
USPS_FlatRateGiftCardEnvelope = 'USPS_FlatRateGiftCardEnvelope',
USPS_FlatRateLegalEnvelope = 'USPS_FlatRateLegalEnvelope',
USPS_FlatRatePaddedEnvelope = 'USPS_FlatRatePaddedEnvelope',
USPS_FlatRateWindowEnvelope = 'USPS_FlatRateWindowEnvelope',
USPS_LargeFlatRateBoardGameBox = 'USPS_LargeFlatRateBoardGameBox',
USPS_LargeFlatRateBox = 'USPS_LargeFlatRateBox',
USPS_Letter = 'USPS_Letter',
USPS_MediumFlatRateBox1 = 'USPS_MediumFlatRateBox1',
USPS_MediumFlatRateBox2 = 'USPS_MediumFlatRateBox2',
USPS_RegionalRateBoxA1 = 'USPS_RegionalRateBoxA1',
USPS_RegionalRateBoxA2 = 'USPS_RegionalRateBoxA2',
USPS_RegionalRateBoxB1 = 'USPS_RegionalRateBoxB1',
USPS_RegionalRateBoxB2 = 'USPS_RegionalRateBoxB2',
USPS_RegionalRateBoxC = 'USPS_RegionalRateBoxC',
USPS_SmallFlatRateBox = 'USPS_SmallFlatRateBox',
USPS_SmallFlatRateEnvelope = 'USPS_SmallFlatRateEnvelope',
}
/* eslint-enable camelcase */

export type PredefinedPackageDimensions =
| 'FedEx_Box_10kg'
| 'FedEx_Box_25kg'
| 'FedEx_Box_Extra_Large_1'
| 'FedEx_Box_Extra_Large_2'
| 'FedEx_Box_Large_1'
| 'FedEx_Box_Large_2'
| 'FedEx_Box_Medium_1'
| 'FedEx_Box_Medium_2'
| 'FedEx_Box_Small_1'
| 'FedEx_Box_Small_2'
| 'FedEx_Envelope'
| 'FedEx_Padded_Pak'
| 'FedEx_Pak_2'
| 'FedEx_Pak_1'
| 'FedEx_Tube'
| 'FedEx_XL_Pak'
| 'UPS_Box_10kg'
| 'UPS_Box_25kg'
| 'UPS_Express_Box'
| 'UPS_Express_Box_Large'
| 'UPS_Express_Box_Medium'
| 'UPS_Express_Box_Small'
| 'UPS_Express_Envelope'
| 'UPS_Express_Hard_Pak'
| 'UPS_Express_Legal_Envelope'
| 'UPS_Express_Pak'
| 'UPS_Express_Tube'
| 'UPS_Laboratory_Pak'
| 'UPS_Pad_Pak'
| 'UPS_Pallet'
| 'USPS_Card'
| 'USPS_Flat'
| 'USPS_FlatRateCardboardEnvelope'
| 'USPS_FlatRateEnvelope'
| 'USPS_FlatRateGiftCardEnvelope'
| 'USPS_FlatRateLegalEnvelope'
| 'USPS_FlatRatePaddedEnvelope'
| 'USPS_FlatRateWindowEnvelope'
| 'USPS_LargeFlatRateBoardGameBox'
| 'USPS_LargeFlatRateBox'
| 'USPS_Letter'
| 'USPS_MediumFlatRateBox1'
| 'USPS_MediumFlatRateBox2'
| 'USPS_RegionalRateBoxA1'
| 'USPS_RegionalRateBoxA2'
| 'USPS_RegionalRateBoxB1'
| 'USPS_RegionalRateBoxB2'
| 'USPS_RegionalRateBoxC'
| 'USPS_SmallFlatRateBox'
| 'USPS_SmallFlatRateEnvelope'
export type PredefinedPackageDimensions = keyof typeof PredefinedPackageDimensionsEnum

export interface PackageDimensions {
Length?: number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
<InputTarget>SHIPMENT_LEVEL</InputTarget>
<StoredValue>
<ValueAsString>ABANDON</ValueAsString>
<DataType>STRING</DataType>
<!-- This was all caps previously. Could that cause a problem? -->
<DataType>STRING</DataType>
<ValueAsBoolean>false</ValueAsBoolean>
<ValueAsInteger>0</ValueAsInteger>
</StoredValue>
Expand Down

0 comments on commit c264821

Please sign in to comment.