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

Commit

Permalink
feat: added list inventory supply by next token
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed May 19, 2020
1 parent 4b912a9 commit c40a241
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ interface ResourceActions {
| 'GetProductCategoriesForSKU'
| 'GetProductCategoriesForASIN'
| 'GetServiceStatus'
[Resource.FulfilmentInventory]: 'ListInventorySupply'
[Resource.FulfilmentInventory]: 'ListInventorySupply' | 'ListInventorySupplyByNextToken'
}

interface Request {
Expand Down
40 changes: 38 additions & 2 deletions src/sections/fulfillment-inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Codec, exactly, GetInterface, number, oneOf, optional, string } from 'p

import { ParsingError } from '../error'
import { HttpClient, RequestMeta, Resource } from '../http'
import { ensureArray, mwsDate, nextToken as nextTokenCodec } from '../parsing'
import { ensureArray, mwsDate, NextToken, nextToken as nextTokenCodec } from '../parsing'

const FULFILLMENT_INVENTORY_API_VERSION = '2010-10-01'

Expand All @@ -25,6 +25,8 @@ enum Condition {
RefurbishedWithWarranty = 'RefurbishedWithWarranty',
Refurbished = 'Refurbished',
Club = 'Club',
// InventorySupplyListByNextToken fixture has condition with an empty string as value
'' = '',
}

enum TimepointType {
Expand Down Expand Up @@ -68,13 +70,26 @@ const InventorySupplyList = Codec.interface({
InventorySupplyList: ensureArray('member', InventorySupply),
})

type InventorySupplyList = GetInterface<typeof InventorySupplyList>

const ListInventorySupplyResponse = Codec.interface({
ListInventorySupplyResponse: Codec.interface({
ListInventorySupplyResult: InventorySupplyList,
}),
})

type InventorySupplyList = GetInterface<typeof InventorySupplyList>
const InventorySupplyListByNextToken = Codec.interface({
NextToken: optional(nextTokenCodec('ListInventorySupply')),
InventorySupplyList: ensureArray('member', InventorySupply),
})

type InventorySupplyListByNextToken = GetInterface<typeof InventorySupplyListByNextToken>

const ListInventorySupplyByNextTokenResponse = Codec.interface({
ListInventorySupplyByNextTokenResponse: Codec.interface({
ListInventorySupplyByNextTokenResult: InventorySupplyListByNextToken,
}),
})

const canonicalizeParameters = (parameters: ListInventorySupplyRequestParameters) => {
return {
Expand Down Expand Up @@ -112,4 +127,25 @@ export class FulfillmentInventory {
},
})
}

async listInventorySupplyByNextToken(
nextToken: NextToken<'ListInventorySupply'>,
): Promise<[InventorySupplyListByNextToken, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.FulfilmentInventory,
version: FULFILLMENT_INVENTORY_API_VERSION,
action: 'ListInventorySupplyByNextToken',
parameters: { NextToken: nextToken.token },
})

return ListInventorySupplyByNextTokenResponse.decode(response).caseOf({
Right: (x) => [
x.ListInventorySupplyByNextTokenResponse.ListInventorySupplyByNextTokenResult,
meta,
],
Left: (error) => {
throw new ParsingError(error)
},
})
}
}
43 changes: 43 additions & 0 deletions test/unit/__snapshots__/fulfillment-inventory.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,46 @@ Array [
},
]
`;

exports[`fulfillment-inventory listInventorySupplyByNextToken returns a parsed model when the response is valid 1`] = `
Array [
Object {
"InventorySupplyList": Array [
Object {
"ASIN": "B00008UI0R",
"Condition": "",
"EarliestAvailability": undefined,
"FNSKU": "B00008UI0R",
"InStockSupplyQuantity": 0,
"SellerSKU": "SampleSKU5",
"SupplyDetail": Array [],
"TotalSupplyQuantity": 0,
},
Object {
"ASIN": "B00000K3CQ",
"Condition": "NewItem",
"EarliestAvailability": Object {
"DateTime": undefined,
"TimepointType": "Immediately",
},
"FNSKU": "X0000000FM",
"InStockSupplyQuantity": 5259,
"SellerSKU": "SampleSKU6",
"SupplyDetail": Array [],
"TotalSupplyQuantity": 5259,
},
],
"NextToken": NextToken {
"action": "ListInventorySupply",
"token": "2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=",
},
},
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": "2020-04-06T10:22:23.582Z",
"requestId": "0",
"timestamp": "2020-05-06T09:22:23.582Z",
},
]
`;

0 comments on commit c40a241

Please sign in to comment.