diff --git a/src/sections/reports.ts b/src/sections/reports.ts index ffc78ee2..98b66041 100644 --- a/src/sections/reports.ts +++ b/src/sections/reports.ts @@ -7,8 +7,8 @@ import { getServiceStatusByResource } from './shared' const REPORTS_API_VERSION = '2009-01-01' /** - * List of supported strings - * Should probably define an enum for this + * List of supported strings. + * Could probably define an enum for this * http://docs.developer.amazonservices.com/en_CA/reports/Reports_ReportType.html#ReportTypeCategories__ListingsReports */ const ReportType = string @@ -167,9 +167,51 @@ const GetReportListByNextTokenResponse = Codec.interface({ }) type GetReportListResult = GetInterface + +const GetReportCount = Codec.interface({ + Count: number, +}) + +const GetReportCountResponse = Codec.interface({ + GetReportCountResponse: Codec.interface({ + GetReportCountResult: GetReportCount, + }), +}) + +interface GetReportCountParameters { + ReportTypeList?: ReportType[] + Acknowledged?: boolean + AvailableFromDate?: Date + AvailableToDate?: Date +} + +type GetReportCount = GetInterface export class Reports { constructor(private httpClient: HttpClient) {} + async getReportCount( + parameters: GetReportCountParameters, + ): Promise<[GetReportCount, RequestMeta]> { + const [response, meta] = await this.httpClient.request('POST', { + resource: Resource.Report, + version: REPORTS_API_VERSION, + action: 'GetReportRequestCount', + parameters: { + 'ReportTypeList.Type': parameters.ReportTypeList, + Acknowledged: parameters.Acknowledged, + AvailableFromDate: parameters.AvailableFromDate?.toISOString(), + AvailableToDate: parameters.AvailableToDate?.toISOString(), + }, + }) + + return GetReportCountResponse.decode(response).caseOf({ + Right: (x) => [x.GetReportCountResponse.GetReportCountResult, meta], + Left: (error) => { + throw new ParsingError(error) + }, + }) + } + async getReportListByNextToken( parameters: GetReportListByNextTokenParameters, ): Promise<[GetReportListResult, RequestMeta]> { diff --git a/test/unit/__snapshots__/reports.test.ts.snap b/test/unit/__snapshots__/reports.test.ts.snap index c3e1f3e0..038f2fdd 100644 --- a/test/unit/__snapshots__/reports.test.ts.snap +++ b/test/unit/__snapshots__/reports.test.ts.snap @@ -27,6 +27,21 @@ Array [ ] `; +exports[`reports getReportCount returns report count if succesful 1`] = ` +Array [ + Object { + "Count": 166, + }, + Object { + "quotaMax": 1000, + "quotaRemaining": 999, + "quotaResetOn": 2020-04-06T10:22:23.582Z, + "requestId": "0", + "timestamp": 2020-05-06T09:22:23.582Z, + }, +] +`; + exports[`reports getReportList returns report info and next token if succesful 1`] = ` Array [ Object {