diff --git a/src/sections/feeds.ts b/src/sections/feeds.ts index 7a846289..2352bc16 100644 --- a/src/sections/feeds.ts +++ b/src/sections/feeds.ts @@ -1,8 +1,8 @@ -import { boolean, Codec, GetInterface, optional, unknown } from 'purify-ts' +import { boolean, Codec, GetInterface, optional, string } from 'purify-ts' import { ParsingError } from '../error' import { HttpClient, RequestMeta, Resource } from '../http' -import { nextToken as nextTokenCodec } from '../parsing' +import { ensureString, mwsDate, NextToken, nextToken as nextTokenCodec } from '../parsing' const FEEDS_API_VERSION = '2009-01-01' interface GetFeedSubmissionListParameters { @@ -14,10 +14,19 @@ interface GetFeedSubmissionListParameters { SubmittedToDate?: Date } +const FeedSubmissionInfo = Codec.interface({ + FeedSubmissionId: ensureString, + FeedType: string, + SubmittedDate: mwsDate, + FeedProcessingStatus: string, + StartedProcessingDate: optional(mwsDate), + CompletedProcessingDate: optional(mwsDate), +}) + const GetFeedSubmissionList = Codec.interface({ HasToken: optional(boolean), NextToken: optional(nextTokenCodec('GetFeedSubmissionList')), - FeedSubmissionInfo: optional(unknown), + FeedSubmissionInfo: optional(FeedSubmissionInfo), }) type GetFeedSubmissionList = GetInterface @@ -28,9 +37,38 @@ const GetFeedSubmissionListResponse = Codec.interface({ }), }) +const GetFeedSubmissionListByNextTokenResponse = Codec.interface({ + GetFeedSubmissionListByNextTokenResponse: Codec.interface({ + GetFeedSubmissionListByNextTokenResult: GetFeedSubmissionList, + }), +}) + export class Feeds { constructor(private httpClient: HttpClient) {} + async getFeedSubmissionListByNextToken( + nextToken: NextToken<'GetFeedSubmissionList'>, + ): Promise<[GetFeedSubmissionList, RequestMeta]> { + const [response, meta] = await this.httpClient.request('POST', { + resource: Resource.Feeds, + version: FEEDS_API_VERSION, + action: 'GetFeedSubmissionListByNextToken', + parameters: { + NextToken: nextToken.token, + }, + }) + + return GetFeedSubmissionListByNextTokenResponse.decode(response).caseOf({ + Right: (x) => [ + x.GetFeedSubmissionListByNextTokenResponse.GetFeedSubmissionListByNextTokenResult, + meta, + ], + Left: (error) => { + throw new ParsingError(error) + }, + }) + } + async getFeedSubmissionList( parameters: GetFeedSubmissionListParameters = {}, ): Promise<[GetFeedSubmissionList, RequestMeta]> { diff --git a/test/unit/__snapshots__/feeds.test.ts.snap b/test/unit/__snapshots__/feeds.test.ts.snap index 5b4ff526..c85e9524 100644 --- a/test/unit/__snapshots__/feeds.test.ts.snap +++ b/test/unit/__snapshots__/feeds.test.ts.snap @@ -5,9 +5,9 @@ Array [ Object { "FeedSubmissionInfo": Object { "FeedProcessingStatus": "_SUBMITTED_", - "FeedSubmissionId": 2291326430, + "FeedSubmissionId": "2291326430", "FeedType": "_POST_PRODUCT_DATA_", - "SubmittedDate": "2009-02-20T02:10:35+00:00", + "SubmittedDate": 2009-02-20T02:10:35.000Z, }, "NextToken": NextToken { "action": "GetFeedSubmissionList", @@ -23,3 +23,27 @@ Array [ }, ] `; + +exports[`feeds getFeedSubmissionListByNextToken returns a next token and feed submission info if succesful 1`] = ` +Array [ + Object { + "FeedSubmissionInfo": Object { + "FeedProcessingStatus": "_SUBMITTED_", + "FeedSubmissionId": "2291326430", + "FeedType": "_POST_PRODUCT_DATA_", + "SubmittedDate": 2009-02-20T02:10:35.000Z, + }, + "NextToken": NextToken { + "action": "GetFeedSubmissionList", + "token": "none", + }, + }, + Object { + "quotaMax": 1000, + "quotaRemaining": 999, + "quotaResetOn": 2020-04-06T10:22:23.582Z, + "requestId": "0", + "timestamp": 2020-05-06T09:22:23.582Z, + }, +] +`;