@intellegens/cornerstone-client 0.0.28 → 0.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Options for configuring read operations.
3
+ *
4
+ * @property {boolean} includeTotalCount - Whether to include the total count of items in the response.
5
+ */
6
+ export type ReadOptions = {
7
+ includeTotalCount: boolean;
8
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import { ReadResultMetadata } from '../..';
2
+ /**
3
+ * Represents a read result containing a collection of results and metadata.
4
+ *
5
+ * @template T The type of result in the collection.
6
+ * @property {T[]} items - The collection of results returned.
7
+ * @property {ReadResultMetadata} metadata - Metadata about the paginated result.
8
+ */
9
+ export type ReadResult<T> = {
10
+ results: T[];
11
+ metadata: ReadResultMetadata;
12
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Metadata associated with a paginated read result.
3
+ *
4
+ * @property {number} [totalCount] - The total number of items available.
5
+ */
6
+ export type ReadResultMetadata = {
7
+ totalCount?: number;
8
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -4,3 +4,6 @@ export * from './ReadSelectedFilteringPropertyDefinitionDto';
4
4
  export * from './ReadSelectedOrderingDefinitionDto';
5
5
  export * from './ReadSelectedOrderingPropertyDefinitionDto';
6
6
  export * from './ReadSelectedPaginationDefinitionDto';
7
+ export * from './ReadOptions';
8
+ export * from './ReadResult';
9
+ export * from './ReadResultMetadata';
@@ -4,3 +4,6 @@ export * from './ReadSelectedFilteringPropertyDefinitionDto';
4
4
  export * from './ReadSelectedOrderingDefinitionDto';
5
5
  export * from './ReadSelectedOrderingPropertyDefinitionDto';
6
6
  export * from './ReadSelectedPaginationDefinitionDto';
7
+ export * from './ReadOptions';
8
+ export * from './ReadResult';
9
+ export * from './ReadResultMetadata';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intellegens/cornerstone-client",
3
- "version": "0.0.28",
3
+ "version": "0.0.30",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -1,6 +1,5 @@
1
1
  import { apiInitializationService } from '../ApiInitializationService';
2
2
  import { ApiReadControllerClient } from '../ApiReadControllerClient';
3
- import { defaultHttpService } from '../HttpService';
4
3
  /**
5
4
  * Generic API client for consuming any Cornerstone CrudController
6
5
  *
@@ -15,7 +14,7 @@ export class ApiCrudControllerClient extends ApiReadControllerClient {
15
14
  * @param baseControllerPath Base path to API controller
16
15
  * @param httpService HTTP service implementation to use for requests
17
16
  */
18
- constructor(baseControllerPath, httpService = defaultHttpService) {
17
+ constructor(baseControllerPath, httpService) {
19
18
  super(baseControllerPath, httpService);
20
19
  }
21
20
  /**
@@ -1,4 +1,4 @@
1
- import { IIdentifiable, ReadSelectedDefinitionDto } from '../../../data';
1
+ import { IIdentifiable, ReadResult, ReadSelectedDefinitionDto, ReadOptions } from '../../../data';
2
2
  import { IHttpService } from '../HttpService';
3
3
  /**
4
4
  * Generic API client for consuming any Cornerstone ReadController
@@ -17,6 +17,14 @@ export declare class ApiReadControllerClient<TKey, TDto extends IIdentifiable<TK
17
17
  */
18
18
  constructor(baseControllerPath: string, httpService?: IHttpService);
19
19
  private _httpService?;
20
+ /**
21
+ * Generates a query string from the provided options.
22
+ *
23
+ * @param {ReadOptions} options - An object containing query option parameters.
24
+ * @param {boolean} options.includeTotalCount - Whether to include the total count of items in the response.
25
+ * @return {string} A query string constructed from the provided options. Returns an empty string if no parameters are provided.
26
+ */
27
+ protected generateQueryParams(options?: ReadOptions): string;
20
28
  /**
21
29
  * Gets globally selected HTTP service
22
30
  */
@@ -24,18 +32,20 @@ export declare class ApiReadControllerClient<TKey, TDto extends IIdentifiable<TK
24
32
  /**
25
33
  * Fetches selected entities based on a filter definition.
26
34
  * @param {any} definition - The filter definition object
27
- * @returns {Promise<TDto[]>} List of entities that match the selection criteria
35
+ * @param options - Optional read options
36
+ * @returns {Promise<ReadResult<TDto>>} The result of the read operation with metadata
28
37
  */
29
- readSelected(definition: ReadSelectedDefinitionDto): Promise<TDto[]>;
38
+ readSelected(definition: ReadSelectedDefinitionDto, options?: ReadOptions): Promise<ReadResult<TDto>>;
30
39
  /**
31
40
  * Fetches a single entity by its ID.
32
41
  * @param {TKey} id - The ID of the entity
33
42
  * @returns {Promise<TDto | undefined>} The requested entity
34
43
  */
35
- readSingle(id: TKey): Promise<TDto>;
44
+ readSingle(id: TKey): Promise<ReadResult<TDto>>;
36
45
  /**
37
46
  * Fetches all entities from the read controller.
38
- * @returns {Promise<TDto[]>} List of all entities
47
+ * @param {ReadOptions} options - Optional read options
48
+ * @returns {Promise<ReadResult<TDto>>} List of all entities with metadata
39
49
  */
40
- readAll(): Promise<TDto[]>;
50
+ readAll(options?: ReadOptions): Promise<ReadResult<TDto>>;
41
51
  }
@@ -1,5 +1,4 @@
1
1
  import { apiInitializationService } from '../ApiInitializationService';
2
- import { defaultHttpService } from '../HttpService';
3
2
  /**
4
3
  * Generic API client for consuming any Cornerstone ReadController
5
4
  *
@@ -15,12 +14,27 @@ export class ApiReadControllerClient {
15
14
  * @param baseControllerPath Base path to API controller
16
15
  * @param httpService HTTP service implementation to use for requests
17
16
  */
18
- constructor(baseControllerPath, httpService = defaultHttpService) {
17
+ constructor(baseControllerPath, httpService) {
19
18
  this.baseControllerPath = baseControllerPath;
20
19
  this._httpService = httpService;
21
20
  }
22
21
  // #region HTTP service
23
22
  _httpService = undefined;
23
+ /**
24
+ * Generates a query string from the provided options.
25
+ *
26
+ * @param {ReadOptions} options - An object containing query option parameters.
27
+ * @param {boolean} options.includeTotalCount - Whether to include the total count of items in the response.
28
+ * @return {string} A query string constructed from the provided options. Returns an empty string if no parameters are provided.
29
+ */
30
+ generateQueryParams(options) {
31
+ if (!options)
32
+ return '';
33
+ const queryParams = [];
34
+ if (options.includeTotalCount)
35
+ queryParams.push(`includeTotalCount=${options.includeTotalCount}`);
36
+ return queryParams.length > 0 ? `?${queryParams.join('&')}` : '';
37
+ }
24
38
  /**
25
39
  * Gets globally selected HTTP service
26
40
  */
@@ -32,11 +46,12 @@ export class ApiReadControllerClient {
32
46
  /**
33
47
  * Fetches selected entities based on a filter definition.
34
48
  * @param {any} definition - The filter definition object
35
- * @returns {Promise<TDto[]>} List of entities that match the selection criteria
49
+ * @param options - Optional read options
50
+ * @returns {Promise<ReadResult<TDto>>} The result of the read operation with metadata
36
51
  */
37
- async readSelected(definition) {
52
+ async readSelected(definition, options) {
38
53
  try {
39
- const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/ReadSelected`);
54
+ const url = (await apiInitializationService.getApiUrl(this.baseControllerPath, `/ReadSelected`)) + this.generateQueryParams(options);
40
55
  const response = await this.httpService.request(url, {
41
56
  method: 'POST',
42
57
  headers: { 'Content-Type': 'application/json' },
@@ -70,11 +85,12 @@ export class ApiReadControllerClient {
70
85
  }
71
86
  /**
72
87
  * Fetches all entities from the read controller.
73
- * @returns {Promise<TDto[]>} List of all entities
88
+ * @param {ReadOptions} options - Optional read options
89
+ * @returns {Promise<ReadResult<TDto>>} List of all entities with metadata
74
90
  */
75
- async readAll() {
91
+ async readAll(options) {
76
92
  try {
77
- const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/ReadAll`);
93
+ const url = (await apiInitializationService.getApiUrl(this.baseControllerPath, `/ReadAll`)) + this.generateQueryParams(options);
78
94
  const response = await this.httpService.request(url, { method: 'GET', credentials: 'include' });
79
95
  if (!response.ok)
80
96
  throw new Error('Failed to fetch all records');
@@ -1,6 +1,6 @@
1
1
  import { ApiCrudControllerClient } from '../ApiCrudControllerClient';
2
2
  import { IHttpService } from '../HttpService';
3
- import { UserDto } from '../../../data';
3
+ import { ReadResult, UserDto, ClaimDto } from '../../../data';
4
4
  /**
5
5
  * Client for user management operations
6
6
  *
@@ -21,18 +21,18 @@ export declare class UserManagementControllerClient<TKey, TUser extends UserDto<
21
21
  * @param id - The ID of the user
22
22
  * @returns List of role names assigned to the user
23
23
  */
24
- getUserRoles(id: TKey): Promise<string[]>;
24
+ getUserRoles(id: TKey): Promise<ReadResult<string>>;
25
25
  /**
26
26
  * Gets the claims assigned to a user
27
27
  * @param id - The ID of the user
28
28
  * @returns List of claims assigned to the user
29
29
  */
30
- getUserClaims(id: TKey): Promise<Record<string, string>>;
30
+ getUserClaims(id: TKey): Promise<ReadResult<ClaimDto>>;
31
31
  /**
32
32
  * Gets all available roles in the system
33
33
  * @returns List of all role names
34
34
  */
35
- getAllRoles(): Promise<string[]>;
35
+ getAllRoles(): Promise<ReadResult<string>>;
36
36
  /**
37
37
  * Changes the password for a user
38
38
  * @param id - The ID of the user
@@ -1,6 +1,5 @@
1
1
  import { ApiCrudControllerClient } from '../ApiCrudControllerClient';
2
2
  import { apiInitializationService } from '../ApiInitializationService';
3
- import { defaultHttpService } from '../HttpService';
4
3
  /**
5
4
  * Client for user management operations
6
5
  *
@@ -15,7 +14,7 @@ export class UserManagementControllerClient extends ApiCrudControllerClient {
15
14
  * @param baseControllerPath Base path to API controller
16
15
  * @param httpService HTTP service implementation to use for requests
17
16
  */
18
- constructor(baseControllerPath, httpService = defaultHttpService) {
17
+ constructor(baseControllerPath, httpService) {
19
18
  super(baseControllerPath, httpService);
20
19
  }
21
20
  /**
@@ -25,7 +24,7 @@ export class UserManagementControllerClient extends ApiCrudControllerClient {
25
24
  */
26
25
  async getUserRoles(id) {
27
26
  try {
28
- const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/GetUserRoles${encodeURIComponent(String(id))}`);
27
+ const url = await apiInitializationService.getApiUrl(this.baseControllerPath, 'GetUserRoles', encodeURIComponent(String(id)));
29
28
  const response = await this.httpService.request(url, {
30
29
  method: 'GET',
31
30
  credentials: 'include',
@@ -45,7 +44,7 @@ export class UserManagementControllerClient extends ApiCrudControllerClient {
45
44
  */
46
45
  async getUserClaims(id) {
47
46
  try {
48
- const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/GetUserClaims/${encodeURIComponent(String(id))}`);
47
+ const url = await apiInitializationService.getApiUrl(this.baseControllerPath, 'GetUserClaims', encodeURIComponent(String(id)));
49
48
  const response = await this.httpService.request(url, {
50
49
  method: 'GET',
51
50
  credentials: 'include',
@@ -64,7 +63,7 @@ export class UserManagementControllerClient extends ApiCrudControllerClient {
64
63
  */
65
64
  async getAllRoles() {
66
65
  try {
67
- const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/GetAllRoles`);
66
+ const url = await apiInitializationService.getApiUrl(this.baseControllerPath, 'GetAllRoles');
68
67
  const response = await this.httpService.request(url, {
69
68
  method: 'GET',
70
69
  credentials: 'include',
@@ -85,7 +84,7 @@ export class UserManagementControllerClient extends ApiCrudControllerClient {
85
84
  */
86
85
  async changePassword(id, newPassword) {
87
86
  try {
88
- const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/ChangePassword/${encodeURIComponent(String(id))}`);
87
+ const url = await apiInitializationService.getApiUrl(this.baseControllerPath, 'ChangePassword', encodeURIComponent(String(id)));
89
88
  const response = await this.httpService.request(url, {
90
89
  method: 'POST',
91
90
  headers: {