diff --git a/src/resources/UsageAnalytics/Read/DataHealth/DataHealth.ts b/src/resources/UsageAnalytics/Read/DataHealth/DataHealth.ts index a831d0a4b..61ef91251 100644 --- a/src/resources/UsageAnalytics/Read/DataHealth/DataHealth.ts +++ b/src/resources/UsageAnalytics/Read/DataHealth/DataHealth.ts @@ -2,6 +2,8 @@ import ReadServiceResource from '../ReadServiceResource.js'; import { DataHealthEventPayloadResponse, DataHealthGetEventPayloadParams, + DataHealthGetFailedInstancesParams, + DataHealthGetFailedInstancesResponse, DataHealthGetGroupDetailParams, DataHealthGetGroupDetailResponse, DataHealthGetGroupListingParams, @@ -22,7 +24,7 @@ export default class DataHealth extends ReadServiceResource { /** * Get health information about events. */ - listEvents(params: DataHealthListEventsParameters, args?: RequestInit) { + listEvents(params: DataHealthListEventsParameters) { return this.api.get( this.buildPathWithOrg(`${DataHealth.baseUrl}/events`, params), ); @@ -31,7 +33,7 @@ export default class DataHealth extends ReadServiceResource { /** * Get original event payload. */ - getEventPayload(params: DataHealthGetEventPayloadParams, args?: RequestInit) { + getEventPayload(params: DataHealthGetEventPayloadParams) { return this.api.get( this.buildPathWithOrg(`${DataHealth.baseUrl}/events/payload`, params), ); @@ -40,7 +42,7 @@ export default class DataHealth extends ReadServiceResource { /** * List applicable facet values in the specified time range. */ - listFacetValues(params: DataHealthListFacetValueParams, args?: RequestInit) { + listFacetValues(params: DataHealthListFacetValueParams) { return this.api.get( this.buildPathWithOrg(`${DataHealth.baseUrl}/facets`, params), ); @@ -49,7 +51,7 @@ export default class DataHealth extends ReadServiceResource { /** * Get general data health information. */ - getOverview(params: DataHealthGetOverviewParams, args?: RequestInit) { + getOverview(params: DataHealthGetOverviewParams) { return this.api.get( this.buildPathWithOrg(`${DataHealth.baseUrl}/overview`, params), ); @@ -58,7 +60,7 @@ export default class DataHealth extends ReadServiceResource { /** * Get health information about groups of validation rules. */ - getGroupListing(params: DataHealthGetGroupListingParams, args?: RequestInit) { + getGroupListing(params: DataHealthGetGroupListingParams) { return this.api.get( this.buildPathWithOrg(`${DataHealth.baseUrl}/groups`, params), ); @@ -67,7 +69,7 @@ export default class DataHealth extends ReadServiceResource { /** * Get health information about validation rules of a specific group. */ - getGroupDetail(params: DataHealthGetGroupDetailParams, args?: RequestInit) { + getGroupDetail(params: DataHealthGetGroupDetailParams) { return this.api.get( this.buildPathWithOrg(`${DataHealth.baseUrl}/groups/detail`, params), ); @@ -76,12 +78,23 @@ export default class DataHealth extends ReadServiceResource { /** * Get a list of unique tracking ids. */ - getTrackingIds(params: DataHealthGetTrackingIdsParams, args?: RequestInit) { + getTrackingIds(params: DataHealthGetTrackingIdsParams) { return this.api.get( this.buildPathWithOrg(`${DataHealth.baseUrl}/facets`, {...params, facet: 'TRACKING_ID'}), ); } + /** + * Get failed instances for a data health criterion + * + * @param params Parameters to fetch data health failed instances. + */ + getFailedInstances(params: DataHealthGetFailedInstancesParams) { + return this.api.get( + this.buildPathWithOrg(`${DataHealth.baseUrl}/criteria/failedInstances`, params), + ); + } + /** * Build the request path, handling the optional `org` query parameter. * diff --git a/src/resources/UsageAnalytics/Read/DataHealth/DataHealthInterfaces.ts b/src/resources/UsageAnalytics/Read/DataHealth/DataHealthInterfaces.ts index b77276d08..a7b1415ee 100644 --- a/src/resources/UsageAnalytics/Read/DataHealth/DataHealthInterfaces.ts +++ b/src/resources/UsageAnalytics/Read/DataHealth/DataHealthInterfaces.ts @@ -310,3 +310,57 @@ export interface DataHealthGetTrackingIdsResponse { */ values: DataHealthFacetValue[]; } + +export interface DataHealthGetFailedInstancesParams extends OrganizationParamParts, TimeRangeParamParts, Paginated { + /** + * The data health criterion for which the failed instances should be returned. + */ + criterionId: string; + /** + * The group for which data health information should be returned. + */ + group: string; + /** + * Optional value of the criterion scope for which failed instances should be returned. + */ + scopeValue?: string; + /** + * Optional set of tracking IDs for which the results should be returned. + */ + trackingId?: string[]; +} + +export interface DataHealthGetFailedInstancesResponse extends PaginatedResponse { + /** + * A collection of failed instances. + */ + failedInstances: DataHealthFailedInstanceEntry[]; +} + +export interface DataHealthFailedInstanceEntry { + /** + * The timestamp of the failed instance. + */ + timestamp: string; + /** + * The ID of the event. + */ + eventId: string; + /** + * The ID of the visit. + */ + visitId: string; + /** + * The client ID of the event. + */ + clientId: string; + /** + * The scope of the datahealth rule. + */ + scope: DataHealthRuleScope; +} + +/** + * The scope of a datahealth rule. + */ +type DataHealthRuleScope = 'EVENT' | 'VISIT'; diff --git a/src/resources/UsageAnalytics/Read/DataHealth/tests/DataHealth.spec.ts b/src/resources/UsageAnalytics/Read/DataHealth/tests/DataHealth.spec.ts index 9385f0985..cd3360ad2 100644 --- a/src/resources/UsageAnalytics/Read/DataHealth/tests/DataHealth.spec.ts +++ b/src/resources/UsageAnalytics/Read/DataHealth/tests/DataHealth.spec.ts @@ -2,6 +2,7 @@ import API from '../../../../../APICore.js'; import DataHealth from '../DataHealth.js'; import { DataHealthGetEventPayloadParams, + DataHealthGetFailedInstancesParams, DataHealthGetGroupDetailParams, DataHealthGetGroupListingParams, DataHealthGetOverviewParams, @@ -125,4 +126,19 @@ describe('DataHealth', () => { ); }); }); + + describe('getFailedInstances', () => { + it('should make a GET call to the data health get failed instances url', async () => { + const datahealthGetFailedInstancesParams: DataHealthGetFailedInstancesParams = { + ...baseParams, + criterionId: 'criterion', + group: 'group', + }; + await dataHealth.getFailedInstances(datahealthGetFailedInstancesParams); + expect(api.get).toHaveBeenCalledTimes(1); + expect(api.get).toHaveBeenCalledWith( + `${DataHealth.baseUrl}/criteria/failedInstances?org=someOrgId&from=1986-04-26T01%3A23%3A58.000Z&to=1986-04-27T02%3A32%3A15.000Z&criterionId=criterion&group=group`, + ); + }); + }); });