diff --git a/src/resources/Enums.ts b/src/resources/Enums.ts index 57adf1b58..971e75c38 100644 --- a/src/resources/Enums.ts +++ b/src/resources/Enums.ts @@ -1066,7 +1066,7 @@ export enum ExportStatus { expired = 'EXPIRED', } -export enum ExportTablesType { +export enum ExportTables { searches = 'SEARCHES', clicks = 'CLICKS', customEvents = 'CUSTOM_EVENTS', diff --git a/src/resources/UsageAnalytics/Read/Exports/Exports.ts b/src/resources/UsageAnalytics/Read/Exports/Exports.ts index acdb5beb7..55f71831d 100644 --- a/src/resources/UsageAnalytics/Read/Exports/Exports.ts +++ b/src/resources/UsageAnalytics/Read/Exports/Exports.ts @@ -9,7 +9,9 @@ import { ExportModel, ExportScheduleModel, GenerateExportParams, + GenerateExportWithBodyParams, GenerateVisitExportParams, + GenerateVisitExportWithBodyParams, RowLimitModel, } from './ExportsInterfaces.js'; @@ -25,11 +27,22 @@ export default class Exports extends ReadServiceResource implements ReadServiceH /** * Generate an export. + * + * @param params The parameters to generate the export with. */ generate(params: GenerateExportParams) { return this.api.post(this.buildPathWithOrg(Exports.baseUrl, params)); } + /** + * Generate an export with the parameters in the request body. + * + * @param params The parameters to generate the export with, passed in the request body. + */ + generateExportWithBody(params: GenerateExportWithBodyParams, args?: RequestInit) { + return this.api.post(this.buildPathWithOrg(`${Exports.baseUrl}/create`), params, args); + } + /** * Get information on an export. * @@ -60,6 +73,8 @@ export default class Exports extends ReadServiceResource implements ReadServiceH /** * Estimate the number of rows in an export. + * + * @param params The date range and other parameters for the export. */ estimateRowsCount(params: EstimateExportParams) { return this.api.get(this.buildPathWithOrg(`${Exports.baseUrl}/estimate`, params)); @@ -67,13 +82,26 @@ export default class Exports extends ReadServiceResource implements ReadServiceH /** * Generate a visit export. + * + * @param params The parameters to generate the visit export with. */ generateVisitExport(params: GenerateVisitExportParams) { return this.api.post(this.buildPathWithOrg(`${Exports.baseUrl}/visits`, params)); } + /** + * Generate a visit export with the parameters in the request body. + * + * @param params The parameters to generate the visit export with, passed in the request body. + */ + generateVisitExportWithBody(params: GenerateVisitExportWithBodyParams, args?: RequestInit) { + return this.api.post(this.buildPathWithOrg(`${Exports.baseUrl}/visits/create`), params, args); + } + /** * Estimate the number of rows in a visit export. + * + * @param params The parameters of the visit export to estimate. */ estimateVisitExportRowsCount(params: EstimateVisitExportParams) { return this.api.get(this.buildPathWithOrg(`${Exports.baseUrl}/visits/estimate`, params)); @@ -88,6 +116,8 @@ export default class Exports extends ReadServiceResource implements ReadServiceH /** * Create an export schedule. + * + * @param model The export schedule to create. */ createSchedule(model: CreateExportScheduleModel) { return this.api.post(this.buildPathWithOrg(`${Exports.baseUrl}/schedules`), model); diff --git a/src/resources/UsageAnalytics/Read/Exports/ExportsInterfaces.ts b/src/resources/UsageAnalytics/Read/Exports/ExportsInterfaces.ts index 566bb8810..d01899d95 100644 --- a/src/resources/UsageAnalytics/Read/Exports/ExportsInterfaces.ts +++ b/src/resources/UsageAnalytics/Read/Exports/ExportsInterfaces.ts @@ -1,4 +1,4 @@ -import {CSVFileFormat, DayOfWeek, ExportScheduleFrequency, ExportStatus, ExportTablesType} from '../../../Enums.js'; +import {CSVFileFormat, DayOfWeek, ExportScheduleFrequency, ExportStatus, ExportTables} from '../../../Enums.js'; import { EventDimensionsExcludeFilterParamParts, EventDimensionsFilterParamParts, @@ -45,7 +45,7 @@ export interface EstimateExportParams extends TimeRangeParamParts, EventDimensio * The tables that will be included. * If not provided, all tables will be included. */ - tables?: ExportTablesType[]; + tables?: ExportTables[]; /** * The filter that will be applied to the click and search events dimensions. * Multiple filter parameters are joined with the AND operator. @@ -87,10 +87,89 @@ export interface GenerateExportParams extends EstimateExportParams { useDisplayNames?: boolean; } +interface BaseGenerateExportWithBodyParams { + /** + * The beginning of the date range, in ISO8601 format (`YYYY-MM-DDThh:mm:ss.sssZ`). + */ + from: string; + /** + * The end of the date range, in ISO8601 format (`YYYY-MM-DDThh:mm:ss.sssZ`). + */ + to: string; + /** + * The file name to use for the export. Can only contain US-ASCII characters. By default, the export ID is used. + */ + filename?: string; + /** + * An optional description for the export. + */ + description?: string; + /** + * The dimensions to export. By default, all dimensions are exported. + */ + dimensions?: string[]; + /** + * The format of the generated CSV files. Defaults to `Excel`. + */ + exportFormat?: CSVFileFormat; + /** + * Whether to use the display names in the export's header. Defaults to `false`, meaning that the API names are used by default. + */ + useDisplayNames?: boolean; +} + +export interface GenerateExportWithBodyParams extends BaseGenerateExportWithBodyParams { + /** + * The filters to apply to dimensions shared by all types of events. + * Multiple filter parameters are joined with the AND operator. + */ + commonFilters?: string[]; + /** + * The filters to apply to the dimensions of click and search events only. + * Multiple filter parameters are joined with the AND operator. + */ + searchesFilters?: string[]; + /** + * The filters to apply to the dimensions of custom events only. + * Multiple filter parameters are joined with the AND operator. + */ + customEventsFilters?: string[]; + /** + * The tables to export. By default, all tables are exported. + */ + tables?: ExportTables[]; +} + +export interface GenerateVisitExportWithBodyParams extends BaseGenerateExportWithBodyParams { + /** + * The filter that will be applied to the events dimensions. + * Multiple filter parameters are joined with the AND operator. + */ + inclusionFilters?: string[]; + /** + * Each specified filter is inverted in order to hide events. + * Multiple filter parameters are joined with the AND operator. + */ + hideEventFilters?: string[]; + /** + * The filter that will be applied to dimensions to exclude events from the results. + * Multiple filter parameters are joined with the AND operator. + * The exclusion filter has precedence over the inclusion filter. + */ + exclusionFilters?: string[]; + /** + * Whether to order the rows by datetime in the export. + * If there are a large number of rows to export, this parameter will be ignored and the data will be unsorted. + * Defaults to `true`. + */ + ordered?: boolean; +} + export interface GenerateVisitExportParams extends GenerateExportParams { /** * Whether to order the rows by datetime in the export. - * If the number of rows exported is too large, this parameter will be ignored and data will be unsorted. + * If there are a large number of rows to export, this parameter will be ignored and the data will be unsorted. + * Defaults to `true`. */ ordered?: boolean; } @@ -118,7 +197,7 @@ export interface CreateExportScheduleModel extends ExportScheduleModelCommonProp searchesFilters?: string[]; customEventsFilters?: string[]; description?: string; - tables?: ExportTablesType[]; + tables?: ExportTables[]; exportFormat?: CSVFileFormat; } diff --git a/src/resources/UsageAnalytics/Read/Exports/tests/Exports.spec.ts b/src/resources/UsageAnalytics/Read/Exports/tests/Exports.spec.ts index 1e5235c2a..4954f050d 100644 --- a/src/resources/UsageAnalytics/Read/Exports/tests/Exports.spec.ts +++ b/src/resources/UsageAnalytics/Read/Exports/tests/Exports.spec.ts @@ -6,7 +6,9 @@ import { EstimateExportParams, EstimateVisitExportParams, GenerateExportParams, + GenerateExportWithBodyParams, GenerateVisitExportParams, + GenerateVisitExportWithBodyParams, } from '../ExportsInterfaces.js'; jest.mock('../../../../../APICore.js'); @@ -24,8 +26,8 @@ describe('Exports', () => { }); describe('list', () => { - it('makes a GET call to the Exports base url', () => { - exports.list(); + it('makes a GET call to the Exports base url', async () => { + await exports.list(); expect(api.get).toHaveBeenCalledTimes(1); expect(api.get).toHaveBeenCalledWith(Exports.baseUrl); @@ -33,22 +35,35 @@ describe('Exports', () => { }); describe('generate', () => { - it('makes a POST call to the Exports base url', () => { + it('makes a POST call to the Exports base url', async () => { const params: GenerateExportParams = { from: '123', to: '456', }; - exports.generate(params); + await exports.generate(params); expect(api.post).toHaveBeenCalledTimes(1); expect(api.post).toHaveBeenCalledWith(`${Exports.baseUrl}?from=123&to=456`); }); }); + describe('generateExportWithBody', () => { + it('makes a POST call to the Exports base url with a request body', async () => { + const params: GenerateExportWithBodyParams = { + from: '123', + to: '456', + }; + await exports.generateExportWithBody(params); + + expect(api.post).toHaveBeenCalledTimes(1); + expect(api.post).toHaveBeenCalledWith(`${Exports.baseUrl}/create`, params, undefined); + }); + }); + describe('get', () => { - it('makes a GET call to the specific Exports url', () => { + it('makes a GET call to the specific Exports url', async () => { const exportId = '🌞'; - exports.get(exportId); + await exports.get(exportId); expect(api.get).toHaveBeenCalledTimes(1); expect(api.get).toHaveBeenCalledWith(`${Exports.baseUrl}/${exportId}?redirect=false`); @@ -56,18 +71,18 @@ describe('Exports', () => { }); describe('getExportDownloadLink', () => { - it('makes a GET call to the specific Exports url', () => { + it('makes a GET call to the specific Exports url', async () => { const exportId = 'Soubame'; - exports.getExportDownloadLink(exportId); + await exports.getExportDownloadLink(exportId); expect(api.get).toHaveBeenCalledTimes(1); expect(api.get).toHaveBeenCalledWith(`${Exports.baseUrl}/${exportId}/downloadlink`); }); }); describe('delete', () => { - it('makes a DELETE call to the specific Exports url', () => { + it('makes a DELETE call to the specific Exports url', async () => { const exportId = '🌞'; - exports.delete(exportId); + await exports.delete(exportId); expect(api.delete).toHaveBeenCalledTimes(1); expect(api.delete).toHaveBeenCalledWith(`${Exports.baseUrl}/${exportId}`); @@ -75,12 +90,12 @@ describe('Exports', () => { }); describe('estimateRowsCount', () => { - it('makes a GET call to the specific Exports url', () => { + it('makes a GET call to the specific Exports url', async () => { const params: EstimateExportParams = { from: '246', to: '135', }; - exports.estimateRowsCount(params); + await exports.estimateRowsCount(params); expect(api.get).toHaveBeenCalledTimes(1); expect(api.get).toHaveBeenCalledWith(`${Exports.baseUrl}/estimate?from=246&to=135`); @@ -88,25 +103,38 @@ describe('Exports', () => { }); describe('generateVisitExport', () => { - it('makes a POST call to the specific Exports url', () => { + it('makes a POST call to the specific Exports url', async () => { const params: GenerateVisitExportParams = { from: '987', to: '654', }; - exports.generateVisitExport(params); + await exports.generateVisitExport(params); expect(api.post).toHaveBeenCalledTimes(1); expect(api.post).toHaveBeenCalledWith(`${Exports.baseUrl}/visits?from=987&to=654`); }); }); + describe('generateVisitExportWithBody', () => { + it('makes a POST call to the specific Exports url with a request body', async () => { + const params: GenerateVisitExportWithBodyParams = { + from: '987', + to: '654', + }; + await exports.generateVisitExportWithBody(params); + + expect(api.post).toHaveBeenCalledTimes(1); + expect(api.post).toHaveBeenCalledWith(`${Exports.baseUrl}/visits/create`, params, undefined); + }); + }); + describe('estimateVisitExportRowsCount', () => { - it('makes a GET call to the specific Exports url', () => { + it('makes a GET call to the specific Exports url', async () => { const params: EstimateVisitExportParams = { from: '741', to: '369', }; - exports.estimateVisitExportRowsCount(params); + await exports.estimateVisitExportRowsCount(params); expect(api.get).toHaveBeenCalledTimes(1); expect(api.get).toHaveBeenCalledWith(`${Exports.baseUrl}/visits/estimate?from=741&to=369`); @@ -114,8 +142,8 @@ describe('Exports', () => { }); describe('listSchedules', () => { - it('makes a GET call to the specific Exports url', () => { - exports.listSchedules(); + it('makes a GET call to the specific Exports url', async () => { + await exports.listSchedules(); expect(api.get).toHaveBeenCalledTimes(1); expect(api.get).toHaveBeenCalledWith(`${Exports.baseUrl}/schedules`); @@ -123,12 +151,12 @@ describe('Exports', () => { }); describe('createSchedule', () => { - it('makes a POST call to the specific Exports url', () => { + it('makes a POST call to the specific Exports url', async () => { const model: CreateExportScheduleModel = { frequency: ExportScheduleFrequency.monthly, timezone: 'Area51', }; - exports.createSchedule(model); + await exports.createSchedule(model); expect(api.post).toHaveBeenCalledTimes(1); expect(api.post).toHaveBeenCalledWith(`${Exports.baseUrl}/schedules`, model); @@ -136,9 +164,9 @@ describe('Exports', () => { }); describe('getSchedule', () => { - it('makes a GET call to the specific Exports url', () => { + it('makes a GET call to the specific Exports url', async () => { const exportScheduleId = '🌞'; - exports.getSchedule(exportScheduleId); + await exports.getSchedule(exportScheduleId); expect(api.get).toHaveBeenCalledTimes(1); expect(api.get).toHaveBeenCalledWith(`${Exports.baseUrl}/schedules/${exportScheduleId}`); @@ -146,13 +174,13 @@ describe('Exports', () => { }); describe('updateSchedule', () => { - it('makes a PUT call to the specific Exports url', () => { + it('makes a PUT call to the specific Exports url', async () => { const exportScheduleId = '🌞'; const model: CreateExportScheduleModel = { frequency: ExportScheduleFrequency.monthly, timezone: 'Area51', }; - exports.updateSchedule(exportScheduleId, model); + await exports.updateSchedule(exportScheduleId, model); expect(api.put).toHaveBeenCalledTimes(1); expect(api.put).toHaveBeenCalledWith(`${Exports.baseUrl}/schedules/${exportScheduleId}`, model); @@ -160,9 +188,9 @@ describe('Exports', () => { }); describe('deleteSchedule', () => { - it('makes a DELETE call to the specific Exports url', () => { + it('makes a DELETE call to the specific Exports url', async () => { const exportScheduleId = '🌞'; - exports.deleteSchedule(exportScheduleId); + await exports.deleteSchedule(exportScheduleId); expect(api.delete).toHaveBeenCalledTimes(1); expect(api.delete).toHaveBeenCalledWith(`${Exports.baseUrl}/schedules/${exportScheduleId}`); @@ -170,8 +198,8 @@ describe('Exports', () => { }); describe('getRowLimit', () => { - it('makes a GET call to the specific Exports url', () => { - exports.getRowLimit(); + it('makes a GET call to the specific Exports url', async () => { + await exports.getRowLimit(); expect(api.get).toHaveBeenCalledTimes(1); expect(api.get).toHaveBeenCalledWith(`${Exports.baseUrl}/rowLimit`); @@ -179,8 +207,8 @@ describe('Exports', () => { }); describe('checkHealth', () => { - it('makes a GET call to the specific Exports url', () => { - exports.checkHealth(); + it('makes a GET call to the specific Exports url', async () => { + await exports.checkHealth(); expect(api.get).toHaveBeenCalledTimes(1); expect(api.get).toHaveBeenCalledWith(`${Exports.baseUrl}/monitoring/health`); @@ -188,8 +216,8 @@ describe('Exports', () => { }); describe('checkStatus', () => { - it('makes a GET call to the specific Exports url', () => { - exports.checkStatus(); + it('makes a GET call to the specific Exports url', async () => { + await exports.checkStatus(); expect(api.get).toHaveBeenCalledTimes(1); expect(api.get).toHaveBeenCalledWith(`${Exports.baseUrl}/status`);