Skip to content

Commit

Permalink
feat: add exports with a request body [UA-8951] (#859)
Browse files Browse the repository at this point in the history
* feat: add exports with a request body [UA-8951]

* fix: add missing annotations, async/await in exports tests [UA-8951]

* fix: elaborated on annotations, added descriptions from Swagger, cleaned up interfaces [UA-8951]

* fix: address comments [UA-8951]
  • Loading branch information
mpayne-coveo authored Sep 30, 2024
1 parent d9fb78f commit a099a95
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/resources/Enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ export enum ExportStatus {
expired = 'EXPIRED',
}

export enum ExportTablesType {
export enum ExportTables {
searches = 'SEARCHES',
clicks = 'CLICKS',
customEvents = 'CUSTOM_EVENTS',
Expand Down
30 changes: 30 additions & 0 deletions src/resources/UsageAnalytics/Read/Exports/Exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {
ExportModel,
ExportScheduleModel,
GenerateExportParams,
GenerateExportWithBodyParams,
GenerateVisitExportParams,
GenerateVisitExportWithBodyParams,
RowLimitModel,
} from './ExportsInterfaces.js';

Expand All @@ -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<ExportModel>(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<ExportModel>(this.buildPathWithOrg(`${Exports.baseUrl}/create`), params, args);
}

/**
* Get information on an export.
*
Expand Down Expand Up @@ -60,20 +73,35 @@ 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<ExportEstimateModel>(this.buildPathWithOrg(`${Exports.baseUrl}/estimate`, params));
}

/**
* Generate a visit export.
*
* @param params The parameters to generate the visit export with.
*/
generateVisitExport(params: GenerateVisitExportParams) {
return this.api.post<ExportModel>(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<ExportModel>(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<ExportEstimateModel>(this.buildPathWithOrg(`${Exports.baseUrl}/visits/estimate`, params));
Expand All @@ -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<ExportScheduleModel>(this.buildPathWithOrg(`${Exports.baseUrl}/schedules`), model);
Expand Down
87 changes: 83 additions & 4 deletions src/resources/UsageAnalytics/Read/Exports/ExportsInterfaces.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -118,7 +197,7 @@ export interface CreateExportScheduleModel extends ExportScheduleModelCommonProp
searchesFilters?: string[];
customEventsFilters?: string[];
description?: string;
tables?: ExportTablesType[];
tables?: ExportTables[];
exportFormat?: CSVFileFormat;
}

Expand Down
Loading

0 comments on commit a099a95

Please sign in to comment.