Skip to content

Commit e5ebc19

Browse files
fix(insights): use Date input, remove isCaseManagement, deduplicate impl
- Change startTime/endTime from number to Date in ElementCountByStatusOptions SDK converts to Unix ms internally via .getTime() - Remove isCaseManagement flag — endpoint is identical for both services - CaseInstancesService delegates to ProcessInstancesService (no duplication) - Update oauth-scopes.md with full scope list (Insights.RealTimeData, Insights, PIMS, OR.Folders.Read) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6115119 commit e5ebc19

11 files changed

Lines changed: 32 additions & 67 deletions

File tree

docs/oauth-scopes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ This page lists the specific OAuth scopes required in external app for each SDK
8383
| `cancel()` | `PIMS` |
8484
| `pause()` | `PIMS` |
8585
| `resume()` | `PIMS` |
86-
| `getElementCountByStatus()` | `Insights.RealTimeData` |
86+
| `getElementCountByStatus()` | `Insights.RealTimeData` `Insights` `PIMS` `OR.Folders.Read` |
8787

8888
## Maestro Cases
8989

@@ -104,7 +104,7 @@ This page lists the specific OAuth scopes required in external app for each SDK
104104
| `getExecutionHistory()` | `PIMS` |
105105
| `getStages()` | `PIMS OR.Execution.Read` |
106106
| `getActionTasks()` | `OR.Tasks` or `OR.Tasks.Read` |
107-
| `getElementCountByStatus()` | `Insights.RealTimeData` |
107+
| `getElementCountByStatus()` | `Insights.RealTimeData` `Insights` `PIMS` `OR.Folders.Read` |
108108

109109
## Conversational Agent
110110

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/models/maestro/case-instances.models.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ export interface CaseInstancesServiceModel {
288288
*
289289
* Returns per-element execution counts (success, fail, terminated, paused, in-progress) and
290290
* duration percentile metrics (min, max, avg, p50, p95, p99) for BPMN elements within a case.
291-
* Internally sets `isCaseManagement: true` to filter for case-specific data.
292291
*
293292
* @param options - Options containing processKey, packageId, time range, and version
294293
* @returns Promise resolving to an array of {@link ElementCountByStatus}
@@ -298,8 +297,8 @@ export interface CaseInstancesServiceModel {
298297
* const elements = await caseInstances.getElementCountByStatus({
299298
* processKey: '<processKey>',
300299
* packageId: '<packageId>',
301-
* startTime: Date.now() - 7 * 24 * 60 * 60 * 1000,
302-
* endTime: Date.now(),
300+
* startTime: new Date('2026-04-01'),
301+
* endTime: new Date(),
303302
* version: '1.0.1'
304303
* });
305304
*

src/models/maestro/insights.types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ export interface ElementCountByStatusOptions {
4141
processKey: string;
4242
/** Package identifier */
4343
packageId: string;
44-
/** Start time as Unix timestamp in milliseconds */
45-
startTime: number;
46-
/** End time as Unix timestamp in milliseconds */
47-
endTime: number;
44+
/** Start of the time range to query */
45+
startTime: Date;
46+
/** End of the time range to query */
47+
endTime: Date;
4848
/** Package version to filter by */
4949
version: string;
5050
}

src/models/maestro/process-instances.models.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ export interface ProcessInstancesServiceModel {
271271
* const elements = await processInstances.getElementCountByStatus({
272272
* processKey: '<processKey>',
273273
* packageId: '<packageId>',
274-
* startTime: Date.now() - 7 * 24 * 60 * 60 * 1000,
275-
* endTime: Date.now(),
274+
* startTime: new Date('2026-04-01'),
275+
* endTime: new Date(),
276276
* version: '1.0.1'
277277
* });
278278
*

src/services/maestro/cases/case-instances.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
ElementCountByStatus,
1717
ElementCountByStatusOptions
1818
} from '../../../models/maestro';
19+
import { ProcessInstancesService } from '../processes/process-instances';
1920
import { TaskGetResponse } from '../../../models/action-center';
2021
import {
2122
CaseJsonResponse
@@ -45,6 +46,7 @@ import { TaskGetAllOptions } from '../../../models/action-center';
4546

4647
export class CaseInstancesService extends BaseService implements CaseInstancesServiceModel {
4748
private taskService: TaskService;
49+
private processInstancesService: ProcessInstancesService;
4850

4951
/**
5052
* Creates an instance of the Case Instances service.
@@ -54,6 +56,7 @@ export class CaseInstancesService extends BaseService implements CaseInstancesSe
5456
constructor(instance: IUiPath) {
5557
super(instance);
5658
this.taskService = new TaskService(instance);
59+
this.processInstancesService = new ProcessInstancesService(instance);
5760
}
5861

5962
/**
@@ -174,23 +177,7 @@ export class CaseInstancesService extends BaseService implements CaseInstancesSe
174177
*/
175178
@track('CaseInstances.GetElementCountByStatus')
176179
async getElementCountByStatus(options: ElementCountByStatusOptions): Promise<ElementCountByStatus[]> {
177-
const requestBody = {
178-
commonParams: {
179-
processKey: options.processKey,
180-
packageId: options.packageId,
181-
startTime: options.startTime,
182-
endTime: options.endTime,
183-
version: options.version,
184-
isCaseManagement: true
185-
}
186-
};
187-
188-
const response = await this.post<ElementCountByStatus[]>(
189-
MAESTRO_ENDPOINTS.INSIGHTS.ELEMENT_COUNT_BY_STATUS,
190-
requestBody
191-
);
192-
193-
return response.data;
180+
return this.processInstancesService.getElementCountByStatus(options);
194181
}
195182

196183
/**

src/services/maestro/processes/process-instances.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ export class ProcessInstancesService extends BaseService implements ProcessInsta
216216
commonParams: {
217217
processKey: options.processKey,
218218
packageId: options.packageId,
219-
startTime: options.startTime,
220-
endTime: options.endTime,
219+
startTime: options.startTime.getTime(),
220+
endTime: options.endTime.getTime(),
221221
version: options.version
222222
}
223223
};

tests/integration/shared/maestro/case-instances.integration.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ describe.each(modes)('Maestro Case Instances - Integration Tests [%s]', (mode) =
276276
const result = await caseInstances.getElementCountByStatus({
277277
processKey: instance.processKey,
278278
packageId: instance.packageId,
279-
startTime: Date.now() - 30 * 24 * 60 * 60 * 1000,
280-
endTime: Date.now(),
279+
startTime: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000),
280+
endTime: new Date(),
281281
version: instance.packageVersion
282282
});
283283

tests/integration/shared/maestro/process-instances.integration.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ describe.each(modes)('Maestro Process Instances - Integration Tests [%s]', (mode
313313
const result = await processInstances.getElementCountByStatus({
314314
processKey: instance.processKey,
315315
packageId: instance.packageId,
316-
startTime: Date.now() - 30 * 24 * 60 * 60 * 1000,
317-
endTime: Date.now(),
316+
startTime: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000),
317+
endTime: new Date(),
318318
version: instance.packageVersion
319319
});
320320

tests/unit/services/maestro/case-instances.test.ts

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -870,47 +870,23 @@ describe('CaseInstancesService', () => {
870870
const options = {
871871
processKey: MAESTRO_TEST_CONSTANTS.CASE_PROCESS_KEY,
872872
packageId: MAESTRO_TEST_CONSTANTS.CASE_PACKAGE_ID,
873-
startTime: 1770748200000,
874-
endTime: 1773253799999,
873+
startTime: new Date('2026-04-01T00:00:00Z'),
874+
endTime: new Date('2026-05-01T00:00:00Z'),
875875
version: MAESTRO_TEST_CONSTANTS.PACKAGE_VERSION
876876
};
877877

878-
it('should return element count by status for case instances with isCaseManagement flag', async () => {
878+
it('should delegate to ProcessInstancesService and return results', async () => {
879879
mockApiClient.post.mockResolvedValue(mockElementCountByStatusResponse);
880880

881881
const result = await service.getElementCountByStatus(options);
882882

883-
expect(mockApiClient.post).toHaveBeenCalledWith(
884-
MAESTRO_ENDPOINTS.INSIGHTS.ELEMENT_COUNT_BY_STATUS,
885-
{
886-
commonParams: {
887-
processKey: MAESTRO_TEST_CONSTANTS.CASE_PROCESS_KEY,
888-
packageId: MAESTRO_TEST_CONSTANTS.CASE_PACKAGE_ID,
889-
startTime: 1770748200000,
890-
endTime: 1773253799999,
891-
version: MAESTRO_TEST_CONSTANTS.PACKAGE_VERSION,
892-
isCaseManagement: true
893-
}
894-
},
895-
{}
896-
);
897-
898883
expect(result).toHaveLength(2);
899884
expect(result[0].elementId).toBe('Event_start');
900885
expect(result[0].successCount).toBe(2);
901886
expect(result[1].failCount).toBe(3);
902887
expect(result[1].inProgressCount).toBe(1);
903888
});
904889

905-
it('should always include isCaseManagement: true in the request body', async () => {
906-
mockApiClient.post.mockResolvedValue([]);
907-
908-
await service.getElementCountByStatus(options);
909-
910-
const callArgs = mockApiClient.post.mock.calls[0];
911-
expect(callArgs[1].commonParams.isCaseManagement).toBe(true);
912-
});
913-
914890
it('should handle API errors', async () => {
915891
const error = new Error(TEST_CONSTANTS.ERROR_MESSAGE);
916892
mockApiClient.post.mockRejectedValue(error);

0 commit comments

Comments
 (0)