diff --git a/src/sections/feeds.ts b/src/sections/feeds.ts index 2352bc16..43a7f93d 100644 --- a/src/sections/feeds.ts +++ b/src/sections/feeds.ts @@ -1,4 +1,4 @@ -import { boolean, Codec, GetInterface, optional, string } from 'purify-ts' +import { boolean, Codec, GetInterface, number, optional, string } from 'purify-ts' import { ParsingError } from '../error' import { HttpClient, RequestMeta, Resource } from '../http' @@ -43,9 +43,95 @@ const GetFeedSubmissionListByNextTokenResponse = Codec.interface({ }), }) +export type FeedType = + | '_POST_PRODUCT_DATA_' + | '_POST_INVENTORY_AVAILABILITY_DATA_' + | '_POST_PRODUCT_OVERRIDES_DATA_' + | '_POST_PRODUCT_PRICING_DATA_' + | '_POST_PRODUCT_IMAGE_DATA_' + | '_POST_PRODUCT_RELATIONSHIP_DATA_' + | '_POST_FLAT_FILE_INVLOADER_DATA_' + | '_POST_FLAT_FILE_LISTINGS_DATA_' + | '_POST_FLAT_FILE_BOOKLOADER_DATA_' + | '_POST_FLAT_FILE_CONVERGENCE_LISTINGS_DATA_' + | '_POST_FLAT_FILE_LISTINGS_DATA_' + | '_POST_FLAT_FILE_PRICEANDQUANTITYONLY_UPDATE_DATA_' + | '_POST_UIEE_BOOKLOADER_DATA_' + | '_POST_STD_ACES_DATA_' + | '_POST_ORDER_ACKNOWLEDGEMENT_DATA_' + | '_POST_PAYMENT_ADJUSTMENT_DATA_' + | '_POST_ORDER_FULFILLMENT_DATA_' + | '_POST_INVOICE_CONFIRMATION_DATA_' + | '_POST_EXPECTED_SHIP_DATE_SOD_' + | '_POST_FLAT_FILE_ORDER_ACKNOWLEDGEMENT_DATA_' + | '_POST_FLAT_FILE_PAYMENT_ADJUSTMENT_DATA_' + | '_POST_FLAT_FILE_FULFILLMENT_DATA_' + | '_POST_EXPECTED_SHIP_DATE_SOD_FLAT_FILE_' + | '_POST_FULFILLMENT_ORDER_REQUEST_DATA_' + | '_POST_FULFILLMENT_ORDER_CANCELLATION_REQUEST_DATA_' + | '_POST_FBA_INBOUND_CARTON_CONTENTS_' + | '_POST_FLAT_FILE_FULFILLMENT_ORDER_REQUEST_DATA_' + | '_POST_FLAT_FILE_FULFILLMENT_ORDER_CANCELLATION_REQUEST_DATA_' + | '_POST_FLAT_FILE_FBA_CREATE_INBOUND_PLAN_' + | '_POST_FLAT_FILE_FBA_UPDATE_INBOUND_PLAN_' + | '_POST_FLAT_FILE_FBA_CREATE_REMOVAL_' + | '_RFQ_UPLOAD_FEED_' + | ' _POST_EASYSHIP_DOCUMENTS_' + +export type FeedProcessingStatus = + | '_AWAITING_ASYNCHRONOUS_REPLY_' + | '_CANCELLED_' + | '_DONE_' + | '_IN_PROGRESS_' + | '_IN_SAFETY_NET_' + | '_SUBMITTED_' + | '_UNCONFIRMED_' + +export interface GetFeedSubmissionCountParameters { + FeedTypeList?: FeedType[] + FeedProcessingStatusList?: FeedProcessingStatus[] + SubmittedFromDate?: Date + SubmittedToDate?: Date +} + +const GetFeedSubmissionCount = Codec.interface({ + Count: number, +}) + +export type GetFeedSubmissionCount = GetInterface + +const GetFeedSubmissionCountResponse = Codec.interface({ + GetFeedSubmissionCountResponse: Codec.interface({ + GetFeedSubmissionCountResult: GetFeedSubmissionCount, + }), +}) + export class Feeds { constructor(private httpClient: HttpClient) {} + async getFeedSubmissionCount( + parameters: GetFeedSubmissionCountParameters = {}, + ): Promise<[GetFeedSubmissionCount, RequestMeta]> { + const [response, meta] = await this.httpClient.request('POST', { + resource: Resource.Feeds, + version: FEEDS_API_VERSION, + action: 'GetFeedSubmissionListByNextToken', + parameters: { + 'FeedTypeList.Type': parameters.FeedTypeList, + 'FeedProcessingStatusList.Status': parameters.FeedProcessingStatusList, + SubmittedFromDate: parameters.SubmittedFromDate?.toISOString(), + SubmittedToDate: parameters.SubmittedToDate?.toISOString(), + }, + }) + + return GetFeedSubmissionCountResponse.decode(response).caseOf({ + Right: (x) => [x.GetFeedSubmissionCountResponse.GetFeedSubmissionCountResult, meta], + Left: (error) => { + throw new ParsingError(error) + }, + }) + } + async getFeedSubmissionListByNextToken( nextToken: NextToken<'GetFeedSubmissionList'>, ): Promise<[GetFeedSubmissionList, RequestMeta]> { diff --git a/test/unit/__snapshots__/feeds.test.ts.snap b/test/unit/__snapshots__/feeds.test.ts.snap index c85e9524..e24f8d4b 100644 --- a/test/unit/__snapshots__/feeds.test.ts.snap +++ b/test/unit/__snapshots__/feeds.test.ts.snap @@ -1,5 +1,20 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`feeds getFeedSubmissionCount returns count of total number of feed submissions if succesful 1`] = ` +Array [ + Object { + "Count": 463, + }, + Object { + "quotaMax": 1000, + "quotaRemaining": 999, + "quotaResetOn": 2020-04-06T10:22:23.582Z, + "requestId": "0", + "timestamp": 2020-05-06T09:22:23.582Z, + }, +] +`; + exports[`feeds getFeedSubmissionList returns a next token and feed submission info if succesful 1`] = ` Array [ Object { diff --git a/test/unit/feeds.test.ts b/test/unit/feeds.test.ts index 9866a534..f69b7f25 100644 --- a/test/unit/feeds.test.ts +++ b/test/unit/feeds.test.ts @@ -12,7 +12,7 @@ describe('feeds', () => { expect(await mockGetFeedSubmissionList.feeds.getFeedSubmissionList()).toMatchSnapshot() }) - it('throws a parsing error when the response is not valid', async () => { + it("throws a parsing error when the response isn't valid", async () => { expect.assertions(1) await expect(() => mockMwsFail.feeds.getFeedSubmissionList()).rejects.toStrictEqual( @@ -42,4 +42,22 @@ describe('feeds', () => { ).rejects.toStrictEqual(new ParsingError(parsingError)) }) }) + + describe('getFeedSubmissionCount', () => { + it('returns count of total number of feed submissions if succesful', async () => { + expect.assertions(1) + + const mockGetFeedSubmissionCount = createMockHttpClient('feeds_get_feed_submission_count') + + expect(await mockGetFeedSubmissionCount.feeds.getFeedSubmissionCount()).toMatchSnapshot() + }) + + it('throws a parsing error when the response is not valid', async () => { + expect.assertions(1) + + await expect(() => mockMwsFail.feeds.getFeedSubmissionCount()).rejects.toStrictEqual( + new ParsingError(parsingError), + ) + }) + }) })