@intellegens/cornerstone-client 0.0.35 → 0.0.36
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.
- package/data/api/dto/crud/CrudMetadata.d.ts +4 -0
- package/data/api/dto/crud/index.d.ts +1 -0
- package/data/api/dto/crud/index.js +1 -0
- package/data/api/dto/index.d.ts +3 -9
- package/data/api/dto/index.js +3 -9
- package/data/api/dto/read/ReadMetadata.d.ts +8 -0
- package/data/api/dto/{ReadSelectedDefinitionDto.d.ts → read/ReadSelectedDefinitionDto.d.ts} +1 -1
- package/data/api/dto/{ReadSelectedOrderingDefinitionDto.d.ts → read/ReadSelectedOrderingDefinitionDto.d.ts} +1 -1
- package/data/api/dto/{ReadSelectedOrderingPropertyDefinitionDto.d.ts → read/ReadSelectedOrderingPropertyDefinitionDto.d.ts} +1 -1
- package/data/api/dto/read/ReadSelectedSearchDefinitionDto.d.ts +18 -0
- package/data/api/dto/{ReadSelectedSearchPropertyDefinitionDto.d.ts → read/ReadSelectedSearchPropertyDefinitionDto.d.ts} +2 -2
- package/data/api/dto/read/index.d.ts +7 -0
- package/data/api/dto/read/index.js +7 -0
- package/data/api/dto/response/ApiError.d.ts +8 -0
- package/data/api/dto/response/ApiResponse.d.ts +15 -0
- package/data/api/dto/response/ApiSuccessResponse.d.ts +12 -0
- package/data/api/dto/response/EmptyMetadata.d.ts +4 -0
- package/data/api/dto/response/EmptyMetadata.js +1 -0
- package/data/api/dto/response/index.d.ts +4 -0
- package/data/api/dto/response/index.js +4 -0
- package/data/api/enum/index.d.ts +2 -4
- package/data/api/enum/index.js +2 -4
- package/data/api/enum/{ReadSelectedComparisonOperator.d.ts → read/ReadSelectedComparisonOperator.d.ts} +21 -1
- package/data/api/enum/{ReadSelectedComparisonOperator.js → read/ReadSelectedComparisonOperator.js} +20 -0
- package/data/api/enum/read/index.d.ts +4 -0
- package/data/api/enum/read/index.js +4 -0
- package/data/api/enum/response/ApiErrorCodes.d.ts +7 -0
- package/data/api/enum/response/ApiErrorCodes.js +8 -0
- package/data/api/enum/response/index.d.ts +1 -0
- package/data/api/enum/response/index.js +1 -0
- package/data/api/index.d.ts +1 -1
- package/data/api/index.js +1 -1
- package/data/api/interface/IIdentifiableSecondary.d.ts +9 -0
- package/data/api/interface/IIdentifiableSecondary.js +1 -0
- package/data/api/interface/index.d.ts +1 -2
- package/data/api/interface/index.js +1 -2
- package/package.json +1 -1
- package/services/api/ApiCrudControllerClient/index.d.ts +3 -3
- package/services/api/ApiCrudControllerClient/index.js +18 -9
- package/services/api/ApiReadControllerClient/index.d.ts +12 -22
- package/services/api/ApiReadControllerClient/index.js +42 -47
- package/services/api/UserManagementControllerClient/index.d.ts +4 -4
- package/services/api/UserManagementControllerClient/index.js +27 -16
- package/services/auth/client/AuthService/index.d.ts +4 -4
- package/services/auth/client/AuthService/index.js +35 -37
- package/services/auth/client/AuthorizationManagementControllerClient/index.d.ts +9 -9
- package/services/auth/client/AuthorizationManagementControllerClient/index.js +42 -33
- package/data/api/dto/ReadOptions.d.ts +0 -8
- package/data/api/dto/ReadResult.d.ts +0 -12
- package/data/api/dto/ReadResultMetadata.d.ts +0 -8
- package/data/api/dto/ReadSelectedSearchDefinitionDto.d.ts +0 -18
- package/data/api/interface/IIdentifiableByGuid.d.ts +0 -9
- package/data/api/interface/IOptionallyIdentifiable.d.ts +0 -11
- /package/data/api/dto/{ReadOptions.js → crud/CrudMetadata.js} +0 -0
- /package/data/api/dto/{ReadResult.js → read/ReadMetadata.js} +0 -0
- /package/data/api/dto/{ReadSelectedDefinitionDto.js → read/ReadSelectedDefinitionDto.js} +0 -0
- /package/data/api/dto/{ReadSelectedOrderingDefinitionDto.js → read/ReadSelectedOrderingDefinitionDto.js} +0 -0
- /package/data/api/dto/{ReadSelectedOrderingPropertyDefinitionDto.js → read/ReadSelectedOrderingPropertyDefinitionDto.js} +0 -0
- /package/data/api/dto/{ReadSelectedPaginationDefinitionDto.d.ts → read/ReadSelectedPaginationDefinitionDto.d.ts} +0 -0
- /package/data/api/dto/{ReadSelectedPaginationDefinitionDto.js → read/ReadSelectedPaginationDefinitionDto.js} +0 -0
- /package/data/api/dto/{ReadSelectedSearchDefinitionDto.js → read/ReadSelectedSearchDefinitionDto.js} +0 -0
- /package/data/api/dto/{ReadSelectedSearchPropertyDefinitionDto.js → read/ReadSelectedSearchPropertyDefinitionDto.js} +0 -0
- /package/data/api/dto/{ReadResultMetadata.js → response/ApiError.js} +0 -0
- /package/data/api/{interface/IIdentifiableByGuid.js → dto/response/ApiResponse.js} +0 -0
- /package/data/api/{interface/IOptionallyIdentifiable.js → dto/response/ApiSuccessResponse.js} +0 -0
- /package/data/api/enum/{ReadSelectedLogicalOperator.d.ts → read/ReadSelectedLogicalOperator.d.ts} +0 -0
- /package/data/api/enum/{ReadSelectedLogicalOperator.js → read/ReadSelectedLogicalOperator.js} +0 -0
- /package/data/api/enum/{ReadSelectedOrderingDirection.d.ts → read/ReadSelectedOrderingDirection.d.ts} +0 -0
- /package/data/api/enum/{ReadSelectedOrderingDirection.js → read/ReadSelectedOrderingDirection.js} +0 -0
- /package/data/api/enum/{ReadSelectedPropertyType.d.ts → read/ReadSelectedPropertyType.d.ts} +0 -0
- /package/data/api/enum/{ReadSelectedPropertyType.js → read/ReadSelectedPropertyType.js} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CrudMetadata';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CrudMetadata';
|
package/data/api/dto/index.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './ReadSelectedOrderingDefinitionDto';
|
|
5
|
-
export * from './ReadSelectedOrderingPropertyDefinitionDto';
|
|
6
|
-
export * from './ReadSelectedPaginationDefinitionDto';
|
|
7
|
-
export * from './ReadOptions';
|
|
8
|
-
export * from './ReadResult';
|
|
9
|
-
export * from './ReadResultMetadata';
|
|
1
|
+
export * from './response';
|
|
2
|
+
export * from './read';
|
|
3
|
+
export * from './crud';
|
package/data/api/dto/index.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './ReadSelectedOrderingDefinitionDto';
|
|
5
|
-
export * from './ReadSelectedOrderingPropertyDefinitionDto';
|
|
6
|
-
export * from './ReadSelectedPaginationDefinitionDto';
|
|
7
|
-
export * from './ReadOptions';
|
|
8
|
-
export * from './ReadResult';
|
|
9
|
-
export * from './ReadResultMetadata';
|
|
1
|
+
export * from './response';
|
|
2
|
+
export * from './read';
|
|
3
|
+
export * from './crud';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReadSelectedPaginationDefinitionDto, ReadSelectedOrderingDefinitionDto, ReadSelectedSearchDefinitionDto } from '
|
|
1
|
+
import { ReadSelectedPaginationDefinitionDto, ReadSelectedOrderingDefinitionDto, ReadSelectedSearchDefinitionDto } from '../../..';
|
|
2
2
|
/**
|
|
3
3
|
* Defines the selection criteria for a controller to fetch multiple records
|
|
4
4
|
*/
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ReadSelectedLogicalOperator, ReadSelectedSearchPropertyDefinitionDto } from '../../..';
|
|
2
|
+
/**
|
|
3
|
+
* Defines the filtering options for a controller, including the logical operator and an array of property definitions.
|
|
4
|
+
*/
|
|
5
|
+
export type ReadSelectedSearchDefinitionDto = {
|
|
6
|
+
/**
|
|
7
|
+
* Logical operator to be used when applying the filters.
|
|
8
|
+
*/
|
|
9
|
+
logicalOperator: ReadSelectedLogicalOperator;
|
|
10
|
+
/**
|
|
11
|
+
* Property-based search criteria.
|
|
12
|
+
*/
|
|
13
|
+
propertyCriteria?: ReadSelectedSearchPropertyDefinitionDto[];
|
|
14
|
+
/**
|
|
15
|
+
* Nested search definitions for complex queries.
|
|
16
|
+
*/
|
|
17
|
+
nestedSearchCriteria?: ReadSelectedSearchPropertyDefinitionDto[];
|
|
18
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReadSelectedComparisonOperator, ReadSelectedPropertyType } from '
|
|
1
|
+
import { ReadSelectedComparisonOperator, ReadSelectedPropertyType } from '../../..';
|
|
2
2
|
/**
|
|
3
3
|
* Defines a property used for searching in a controller.
|
|
4
4
|
*/
|
|
@@ -93,7 +93,7 @@ type Partial_ReadSelectedSearchPropertyDefinition_TypedComparisonOperators = {
|
|
|
93
93
|
/**
|
|
94
94
|
* The comparison operator to use for the search.
|
|
95
95
|
*/
|
|
96
|
-
comparisonOperator: ReadSelectedComparisonOperator.Equal | ReadSelectedComparisonOperator.NotEqual | ReadSelectedComparisonOperator.Contains | ReadSelectedComparisonOperator.StartsWith | ReadSelectedComparisonOperator.EndsWith;
|
|
96
|
+
comparisonOperator: ReadSelectedComparisonOperator.Equal | ReadSelectedComparisonOperator.NotEqual | ReadSelectedComparisonOperator.Contains | ReadSelectedComparisonOperator.StartsWith | ReadSelectedComparisonOperator.EndsWith | ReadSelectedComparisonOperator.IContains | ReadSelectedComparisonOperator.IStartsWith | ReadSelectedComparisonOperator.IEndsWith | ReadSelectedComparisonOperator.IEqual | ReadSelectedComparisonOperator.INotEqual;
|
|
97
97
|
} | {
|
|
98
98
|
/**
|
|
99
99
|
* The type of the property value being searched.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './ReadMetadata';
|
|
2
|
+
export * from './ReadSelectedSearchPropertyDefinitionDto';
|
|
3
|
+
export * from './ReadSelectedOrderingDefinitionDto';
|
|
4
|
+
export * from './ReadSelectedOrderingPropertyDefinitionDto';
|
|
5
|
+
export * from './ReadSelectedPaginationDefinitionDto';
|
|
6
|
+
export * from './ReadSelectedDefinitionDto';
|
|
7
|
+
export * from './ReadSelectedSearchDefinitionDto';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './ReadMetadata';
|
|
2
|
+
export * from './ReadSelectedSearchPropertyDefinitionDto';
|
|
3
|
+
export * from './ReadSelectedOrderingDefinitionDto';
|
|
4
|
+
export * from './ReadSelectedOrderingPropertyDefinitionDto';
|
|
5
|
+
export * from './ReadSelectedPaginationDefinitionDto';
|
|
6
|
+
export * from './ReadSelectedDefinitionDto';
|
|
7
|
+
export * from './ReadSelectedSearchDefinitionDto';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ApiError } from '../../..';
|
|
2
|
+
/**
|
|
3
|
+
* Represents an API response containing a result and metadata, or an error.
|
|
4
|
+
*
|
|
5
|
+
* @template T The type of result
|
|
6
|
+
* @template TMetadata The type of metadata
|
|
7
|
+
* @property {T} result - The result returned
|
|
8
|
+
* @property {TMetadata} metadata - Metadata about the result
|
|
9
|
+
*/
|
|
10
|
+
export type ApiResponse<T, TMetadata> = {
|
|
11
|
+
success: boolean;
|
|
12
|
+
result: T;
|
|
13
|
+
metadata: TMetadata;
|
|
14
|
+
error: ApiError;
|
|
15
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an successful API response containing a result and metadata.
|
|
3
|
+
*
|
|
4
|
+
* @template T The type of result
|
|
5
|
+
* @template TMetadata The type of metadata
|
|
6
|
+
* @property {T} result - The result returned
|
|
7
|
+
* @property {TMetadata} metadata - Metadata about the result
|
|
8
|
+
*/
|
|
9
|
+
export type ApiSuccessResponse<T, TMetadata> = {
|
|
10
|
+
result: T;
|
|
11
|
+
metadata: TMetadata;
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/data/api/enum/index.d.ts
CHANGED
package/data/api/enum/index.js
CHANGED
|
@@ -45,5 +45,25 @@ export declare enum ReadSelectedComparisonOperator {
|
|
|
45
45
|
/**
|
|
46
46
|
* Represents the ends with comparison operator.
|
|
47
47
|
*/
|
|
48
|
-
EndsWith = 202
|
|
48
|
+
EndsWith = 202,
|
|
49
|
+
/**
|
|
50
|
+
* Represents the contains comparison operator (case-insensitive).
|
|
51
|
+
*/
|
|
52
|
+
IContains = 203,
|
|
53
|
+
/**
|
|
54
|
+
* Represents the starts with comparison operator (case-insensitive).
|
|
55
|
+
*/
|
|
56
|
+
IStartsWith = 204,
|
|
57
|
+
/**
|
|
58
|
+
* Represents the ends with comparison operator (case-insensitive).
|
|
59
|
+
*/
|
|
60
|
+
IEndsWith = 205,
|
|
61
|
+
/**
|
|
62
|
+
* Represents the equal comparison operator (case-insensitive).
|
|
63
|
+
*/
|
|
64
|
+
IEqual = 206,
|
|
65
|
+
/**
|
|
66
|
+
* Represents the not equal comparison operator (case-insensitive).
|
|
67
|
+
*/
|
|
68
|
+
INotEqual = 207
|
|
49
69
|
}
|
package/data/api/enum/{ReadSelectedComparisonOperator.js → read/ReadSelectedComparisonOperator.js}
RENAMED
|
@@ -52,5 +52,25 @@ export var ReadSelectedComparisonOperator;
|
|
|
52
52
|
* Represents the ends with comparison operator.
|
|
53
53
|
*/
|
|
54
54
|
ReadSelectedComparisonOperator[ReadSelectedComparisonOperator["EndsWith"] = 202] = "EndsWith";
|
|
55
|
+
/**
|
|
56
|
+
* Represents the contains comparison operator (case-insensitive).
|
|
57
|
+
*/
|
|
58
|
+
ReadSelectedComparisonOperator[ReadSelectedComparisonOperator["IContains"] = 203] = "IContains";
|
|
59
|
+
/**
|
|
60
|
+
* Represents the starts with comparison operator (case-insensitive).
|
|
61
|
+
*/
|
|
62
|
+
ReadSelectedComparisonOperator[ReadSelectedComparisonOperator["IStartsWith"] = 204] = "IStartsWith";
|
|
63
|
+
/**
|
|
64
|
+
* Represents the ends with comparison operator (case-insensitive).
|
|
65
|
+
*/
|
|
66
|
+
ReadSelectedComparisonOperator[ReadSelectedComparisonOperator["IEndsWith"] = 205] = "IEndsWith";
|
|
67
|
+
/**
|
|
68
|
+
* Represents the equal comparison operator (case-insensitive).
|
|
69
|
+
*/
|
|
70
|
+
ReadSelectedComparisonOperator[ReadSelectedComparisonOperator["IEqual"] = 206] = "IEqual";
|
|
71
|
+
/**
|
|
72
|
+
* Represents the not equal comparison operator (case-insensitive).
|
|
73
|
+
*/
|
|
74
|
+
ReadSelectedComparisonOperator[ReadSelectedComparisonOperator["INotEqual"] = 207] = "INotEqual";
|
|
55
75
|
//#endregion
|
|
56
76
|
})(ReadSelectedComparisonOperator || (ReadSelectedComparisonOperator = {}));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents available error codes to be returned as part of the ApiResponse object
|
|
3
|
+
*/
|
|
4
|
+
export var ApiErrorCodes;
|
|
5
|
+
(function (ApiErrorCodes) {
|
|
6
|
+
ApiErrorCodes[ApiErrorCodes["NotFound"] = 404] = "NotFound";
|
|
7
|
+
ApiErrorCodes[ApiErrorCodes["BadRequest"] = 400] = "BadRequest";
|
|
8
|
+
})(ApiErrorCodes || (ApiErrorCodes = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ApiErrorCodes';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ApiErrorCodes';
|
package/data/api/index.d.ts
CHANGED
package/data/api/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ApiReadControllerClient } from '../ApiReadControllerClient';
|
|
2
|
-
import { IIdentifiable,
|
|
2
|
+
import { IIdentifiable, ApiSuccessResponse, EmptyMetadata } from '../../../data';
|
|
3
3
|
import { IHttpService } from '../HttpService';
|
|
4
4
|
/**
|
|
5
5
|
* Generic API client for consuming any Cornerstone CrudController
|
|
@@ -21,14 +21,14 @@ export declare class ApiCrudControllerClient<TKey, TDto extends IIdentifiable<TK
|
|
|
21
21
|
* @param dto - Insert request DTO
|
|
22
22
|
* @returns The created entity DTO
|
|
23
23
|
*/
|
|
24
|
-
create(dto: TDto): Promise<
|
|
24
|
+
create(dto: TDto): Promise<ApiSuccessResponse<TDto, EmptyMetadata>>;
|
|
25
25
|
/**
|
|
26
26
|
* Updates an existing entity.
|
|
27
27
|
* @param id - The ID of the entity to update
|
|
28
28
|
* @param dto - Update request DTO
|
|
29
29
|
* @returns The updated entity DTO
|
|
30
30
|
*/
|
|
31
|
-
update(id: TKey, dto: TDto): Promise<
|
|
31
|
+
update(id: TKey, dto: TDto): Promise<ApiSuccessResponse<TDto, EmptyMetadata>>;
|
|
32
32
|
/**
|
|
33
33
|
* Deletes an entity by ID.
|
|
34
34
|
* @param id - The ID of the entity to delete
|
|
@@ -25,17 +25,21 @@ export class ApiCrudControllerClient extends ApiReadControllerClient {
|
|
|
25
25
|
async create(dto) {
|
|
26
26
|
try {
|
|
27
27
|
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/Create`);
|
|
28
|
-
const
|
|
28
|
+
const res = await this.httpService.request(url, {
|
|
29
29
|
method: 'POST',
|
|
30
30
|
headers: { 'Content-Type': 'application/json' },
|
|
31
31
|
body: JSON.stringify(dto),
|
|
32
32
|
credentials: 'include',
|
|
33
33
|
});
|
|
34
|
-
if (!
|
|
35
|
-
throw
|
|
36
|
-
|
|
34
|
+
if (!res.ok)
|
|
35
|
+
throw undefined;
|
|
36
|
+
const { success, result, metadata, error } = (await res.json());
|
|
37
|
+
if (!success)
|
|
38
|
+
throw new Error(error.message);
|
|
39
|
+
return { result, metadata };
|
|
37
40
|
}
|
|
38
41
|
catch (err) {
|
|
42
|
+
// TODO: Extract error from well-formed response
|
|
39
43
|
throw err instanceof Error ? err : new Error('Unknown error creating record');
|
|
40
44
|
}
|
|
41
45
|
}
|
|
@@ -48,17 +52,21 @@ export class ApiCrudControllerClient extends ApiReadControllerClient {
|
|
|
48
52
|
async update(id, dto) {
|
|
49
53
|
try {
|
|
50
54
|
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/Update?id=${encodeURIComponent(String(id))}`);
|
|
51
|
-
const
|
|
55
|
+
const res = await this.httpService.request(url, {
|
|
52
56
|
method: 'PUT',
|
|
53
57
|
headers: { 'Content-Type': 'application/json' },
|
|
54
58
|
body: JSON.stringify(dto),
|
|
55
59
|
credentials: 'include',
|
|
56
60
|
});
|
|
57
|
-
if (!
|
|
58
|
-
throw
|
|
59
|
-
|
|
61
|
+
if (!res.ok)
|
|
62
|
+
throw undefined;
|
|
63
|
+
const { success, result, metadata, error } = (await res.json());
|
|
64
|
+
if (!success)
|
|
65
|
+
throw new Error(error.message);
|
|
66
|
+
return { result, metadata };
|
|
60
67
|
}
|
|
61
68
|
catch (err) {
|
|
69
|
+
// TODO: Extract error from well-formed response
|
|
62
70
|
throw err instanceof Error ? err : new Error('Unknown error updating record');
|
|
63
71
|
}
|
|
64
72
|
}
|
|
@@ -74,9 +82,10 @@ export class ApiCrudControllerClient extends ApiReadControllerClient {
|
|
|
74
82
|
credentials: 'include',
|
|
75
83
|
});
|
|
76
84
|
if (!response.ok)
|
|
77
|
-
throw
|
|
85
|
+
throw undefined;
|
|
78
86
|
}
|
|
79
87
|
catch (err) {
|
|
88
|
+
// TODO: Extract error from well-formed response
|
|
80
89
|
throw err instanceof Error ? err : new Error('Unknown error deleting record');
|
|
81
90
|
}
|
|
82
91
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IIdentifiable,
|
|
1
|
+
import { IIdentifiable, ApiSuccessResponse, ReadSelectedDefinitionDto, ReadMetadata, EmptyMetadata } from '../../../data';
|
|
2
2
|
import { IHttpService } from '../HttpService';
|
|
3
3
|
/**
|
|
4
4
|
* Generic API client for consuming any Cornerstone ReadController
|
|
@@ -17,35 +17,25 @@ 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;
|
|
28
20
|
/**
|
|
29
21
|
* Gets globally selected HTTP service
|
|
30
22
|
*/
|
|
31
23
|
protected get httpService(): IHttpService;
|
|
32
24
|
/**
|
|
33
|
-
* Fetches
|
|
34
|
-
* @
|
|
35
|
-
* @param options - Optional read options
|
|
36
|
-
* @returns {Promise<ReadResult<TDto>>} The result of the read operation with metadata
|
|
25
|
+
* Fetches all entities from the read controller.
|
|
26
|
+
* @returns {Promise<ApiSuccessResponse<TDto[], ReadMetadata>>} List of all entities with metadata
|
|
37
27
|
*/
|
|
38
|
-
|
|
28
|
+
readAll(): Promise<ApiSuccessResponse<TDto[], ReadMetadata>>;
|
|
39
29
|
/**
|
|
40
|
-
* Fetches
|
|
41
|
-
* @param {
|
|
42
|
-
* @returns {Promise<TDto
|
|
30
|
+
* Fetches selected entities based on a filter definition.
|
|
31
|
+
* @param {any} definition - The filter definition object
|
|
32
|
+
* @returns {Promise<ApiSuccessResponse<TDto[], ReadMetadata>>} The result of the read operation with metadata
|
|
43
33
|
*/
|
|
44
|
-
|
|
34
|
+
readSelected(definition: ReadSelectedDefinitionDto): Promise<ApiSuccessResponse<TDto[], ReadMetadata>>;
|
|
45
35
|
/**
|
|
46
|
-
* Fetches
|
|
47
|
-
* @param {
|
|
48
|
-
* @returns {Promise<
|
|
36
|
+
* Fetches a single entity by its ID.
|
|
37
|
+
* @param {TKey} id - The ID of the entity
|
|
38
|
+
* @returns {Promise<ApiSuccessResponse<TDto, EmptyMetadata>>} The requested entity
|
|
49
39
|
*/
|
|
50
|
-
|
|
40
|
+
readSingle(id: TKey): Promise<ApiSuccessResponse<TDto, EmptyMetadata>>;
|
|
51
41
|
}
|
|
@@ -20,21 +20,6 @@ export class ApiReadControllerClient {
|
|
|
20
20
|
}
|
|
21
21
|
// #region HTTP service
|
|
22
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
|
-
}
|
|
38
23
|
/**
|
|
39
24
|
* Gets globally selected HTTP service
|
|
40
25
|
*/
|
|
@@ -44,60 +29,70 @@ export class ApiReadControllerClient {
|
|
|
44
29
|
// #endregion
|
|
45
30
|
// #region API
|
|
46
31
|
/**
|
|
47
|
-
* Fetches
|
|
48
|
-
* @
|
|
49
|
-
* @param options - Optional read options
|
|
50
|
-
* @returns {Promise<ReadResult<TDto>>} The result of the read operation with metadata
|
|
32
|
+
* Fetches all entities from the read controller.
|
|
33
|
+
* @returns {Promise<ApiSuccessResponse<TDto[], ReadMetadata>>} List of all entities with metadata
|
|
51
34
|
*/
|
|
52
|
-
async
|
|
35
|
+
async readAll() {
|
|
53
36
|
try {
|
|
54
|
-
const url =
|
|
55
|
-
const
|
|
37
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/ReadAll`);
|
|
38
|
+
const res = await this.httpService.request(url, { method: 'GET', credentials: 'include' });
|
|
39
|
+
if (!res.ok)
|
|
40
|
+
throw undefined;
|
|
41
|
+
const { success, result, metadata, error } = (await res.json());
|
|
42
|
+
if (!success)
|
|
43
|
+
throw new Error(error.message);
|
|
44
|
+
return { result, metadata };
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
// TODO: Extract error from well-formed response
|
|
48
|
+
throw err instanceof Error ? err : new Error('Unknown error fetching all records');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Fetches selected entities based on a filter definition.
|
|
53
|
+
* @param {any} definition - The filter definition object
|
|
54
|
+
* @returns {Promise<ApiSuccessResponse<TDto[], ReadMetadata>>} The result of the read operation with metadata
|
|
55
|
+
*/
|
|
56
|
+
async readSelected(definition) {
|
|
57
|
+
try {
|
|
58
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/ReadSelected`);
|
|
59
|
+
const res = await this.httpService.request(url, {
|
|
56
60
|
method: 'POST',
|
|
57
61
|
headers: { 'Content-Type': 'application/json' },
|
|
58
62
|
body: JSON.stringify(definition),
|
|
59
63
|
credentials: 'include',
|
|
60
64
|
});
|
|
61
|
-
if (!
|
|
62
|
-
throw
|
|
63
|
-
|
|
65
|
+
if (!res.ok)
|
|
66
|
+
throw undefined;
|
|
67
|
+
const { success, result, metadata, error } = (await res.json());
|
|
68
|
+
if (!success)
|
|
69
|
+
throw new Error(error.message);
|
|
70
|
+
return { result, metadata };
|
|
64
71
|
}
|
|
65
72
|
catch (err) {
|
|
73
|
+
// TODO: Extract error from well-formed response
|
|
66
74
|
throw err instanceof Error ? err : new Error('Unknown error fetching selected records');
|
|
67
75
|
}
|
|
68
76
|
}
|
|
69
77
|
/**
|
|
70
78
|
* Fetches a single entity by its ID.
|
|
71
79
|
* @param {TKey} id - The ID of the entity
|
|
72
|
-
* @returns {Promise<TDto
|
|
80
|
+
* @returns {Promise<ApiSuccessResponse<TDto, EmptyMetadata>>} The requested entity
|
|
73
81
|
*/
|
|
74
82
|
async readSingle(id) {
|
|
75
83
|
try {
|
|
76
84
|
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/ReadSingle?id=${encodeURIComponent(String(id))}`);
|
|
77
|
-
const
|
|
78
|
-
if (!
|
|
79
|
-
throw
|
|
80
|
-
|
|
85
|
+
const res = await this.httpService.request(url, { method: 'GET', credentials: 'include' });
|
|
86
|
+
if (!res.ok)
|
|
87
|
+
throw undefined;
|
|
88
|
+
const { success, result, metadata, error } = (await res.json());
|
|
89
|
+
if (!success)
|
|
90
|
+
throw new Error(error.message);
|
|
91
|
+
return { result, metadata };
|
|
81
92
|
}
|
|
82
93
|
catch (err) {
|
|
94
|
+
// TODO: Extract error from well-formed response
|
|
83
95
|
throw err instanceof Error ? err : new Error('Unknown error fetching single record');
|
|
84
96
|
}
|
|
85
97
|
}
|
|
86
|
-
/**
|
|
87
|
-
* Fetches all entities from the read controller.
|
|
88
|
-
* @param {ReadOptions} options - Optional read options
|
|
89
|
-
* @returns {Promise<ReadResult<TDto>>} List of all entities with metadata
|
|
90
|
-
*/
|
|
91
|
-
async readAll(options) {
|
|
92
|
-
try {
|
|
93
|
-
const url = (await apiInitializationService.getApiUrl(this.baseControllerPath, `/ReadAll`)) + this.generateQueryParams(options);
|
|
94
|
-
const response = await this.httpService.request(url, { method: 'GET', credentials: 'include' });
|
|
95
|
-
if (!response.ok)
|
|
96
|
-
throw new Error('Failed to fetch all records');
|
|
97
|
-
return response.json();
|
|
98
|
-
}
|
|
99
|
-
catch (err) {
|
|
100
|
-
throw err instanceof Error ? err : new Error('Unknown error fetching all records');
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
98
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ApiCrudControllerClient } from '../ApiCrudControllerClient';
|
|
2
2
|
import { IHttpService } from '../HttpService';
|
|
3
|
-
import {
|
|
3
|
+
import { UserDto, ClaimDto, ReadMetadata, ApiSuccessResponse } 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<
|
|
24
|
+
getUserRoles(id: TKey): Promise<ApiSuccessResponse<string[], ReadMetadata>>;
|
|
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<
|
|
30
|
+
getUserClaims(id: TKey): Promise<ApiSuccessResponse<ClaimDto[], ReadMetadata>>;
|
|
31
31
|
/**
|
|
32
32
|
* Gets all available roles in the system
|
|
33
33
|
* @returns List of all role names
|
|
34
34
|
*/
|
|
35
|
-
getAllRoles(): Promise<
|
|
35
|
+
getAllRoles(): Promise<ApiSuccessResponse<string[], ReadMetadata>>;
|
|
36
36
|
/**
|
|
37
37
|
* Changes the password for a user
|
|
38
38
|
* @param id - The ID of the user
|
|
@@ -25,15 +25,19 @@ export class UserManagementControllerClient extends ApiCrudControllerClient {
|
|
|
25
25
|
async getUserRoles(id) {
|
|
26
26
|
try {
|
|
27
27
|
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, 'GetUserRoles', encodeURIComponent(String(id)));
|
|
28
|
-
const
|
|
28
|
+
const res = await this.httpService.request(url, {
|
|
29
29
|
method: 'GET',
|
|
30
30
|
credentials: 'include',
|
|
31
31
|
});
|
|
32
|
-
if (!
|
|
33
|
-
throw
|
|
34
|
-
|
|
32
|
+
if (!res.ok)
|
|
33
|
+
throw undefined;
|
|
34
|
+
const { success, result, metadata, error } = (await res.json());
|
|
35
|
+
if (!success)
|
|
36
|
+
throw new Error(error.message);
|
|
37
|
+
return { result, metadata };
|
|
35
38
|
}
|
|
36
39
|
catch (err) {
|
|
40
|
+
// TODO: Extract error from well-formed response
|
|
37
41
|
throw err instanceof Error ? err : new Error('Unknown error fetching user roles');
|
|
38
42
|
}
|
|
39
43
|
}
|
|
@@ -45,15 +49,19 @@ export class UserManagementControllerClient extends ApiCrudControllerClient {
|
|
|
45
49
|
async getUserClaims(id) {
|
|
46
50
|
try {
|
|
47
51
|
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, 'GetUserClaims', encodeURIComponent(String(id)));
|
|
48
|
-
const
|
|
52
|
+
const res = await this.httpService.request(url, {
|
|
49
53
|
method: 'GET',
|
|
50
54
|
credentials: 'include',
|
|
51
55
|
});
|
|
52
|
-
if (!
|
|
53
|
-
throw
|
|
54
|
-
|
|
56
|
+
if (!res.ok)
|
|
57
|
+
throw undefined;
|
|
58
|
+
const { success, result, metadata, error } = (await res.json());
|
|
59
|
+
if (!success)
|
|
60
|
+
throw new Error(error.message);
|
|
61
|
+
return { result, metadata };
|
|
55
62
|
}
|
|
56
63
|
catch (err) {
|
|
64
|
+
// TODO: Extract error from well-formed response
|
|
57
65
|
throw err instanceof Error ? err : new Error('Unknown error fetching user claims');
|
|
58
66
|
}
|
|
59
67
|
}
|
|
@@ -64,15 +72,19 @@ export class UserManagementControllerClient extends ApiCrudControllerClient {
|
|
|
64
72
|
async getAllRoles() {
|
|
65
73
|
try {
|
|
66
74
|
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, 'GetAllRoles');
|
|
67
|
-
const
|
|
75
|
+
const res = await this.httpService.request(url, {
|
|
68
76
|
method: 'GET',
|
|
69
77
|
credentials: 'include',
|
|
70
78
|
});
|
|
71
|
-
if (!
|
|
72
|
-
throw
|
|
73
|
-
|
|
79
|
+
if (!res.ok)
|
|
80
|
+
throw undefined;
|
|
81
|
+
const { success, result, metadata, error } = (await res.json());
|
|
82
|
+
if (!success)
|
|
83
|
+
throw new Error(error.message);
|
|
84
|
+
return { result, metadata };
|
|
74
85
|
}
|
|
75
86
|
catch (err) {
|
|
87
|
+
// TODO: Extract error from well-formed response
|
|
76
88
|
throw err instanceof Error ? err : new Error('Unknown error fetching all roles');
|
|
77
89
|
}
|
|
78
90
|
}
|
|
@@ -93,12 +105,11 @@ export class UserManagementControllerClient extends ApiCrudControllerClient {
|
|
|
93
105
|
body: JSON.stringify(newPassword),
|
|
94
106
|
credentials: 'include',
|
|
95
107
|
});
|
|
96
|
-
if (!response.ok)
|
|
97
|
-
|
|
98
|
-
throw new Error(errorText || 'Failed to change password');
|
|
99
|
-
}
|
|
108
|
+
if (!response.ok)
|
|
109
|
+
throw undefined;
|
|
100
110
|
}
|
|
101
111
|
catch (err) {
|
|
112
|
+
// TODO: Extract error from well-formed response
|
|
102
113
|
throw err instanceof Error ? err : new Error('Unknown error changing password');
|
|
103
114
|
}
|
|
104
115
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserDto, UserInfoDto } from '../../../../data';
|
|
1
|
+
import { ApiSuccessResponse, EmptyMetadata, UserDto, UserInfoDto } from '../../../../data';
|
|
2
2
|
export { UserDto, UserInfoDto };
|
|
3
3
|
/**
|
|
4
4
|
* AuthService class is responsible for managing user authentication operations.
|
|
@@ -25,7 +25,7 @@ export declare class AuthService<TKey, TUser extends UserDto<TKey> = UserDto<TKe
|
|
|
25
25
|
* @return {Promise<TUser>} Currently logged in user's details
|
|
26
26
|
* @throws {Error} Error if fetch fails
|
|
27
27
|
*/
|
|
28
|
-
whoAmI(): Promise<TUser | undefined
|
|
28
|
+
whoAmI(): Promise<ApiSuccessResponse<TUser | undefined, EmptyMetadata>>;
|
|
29
29
|
/**
|
|
30
30
|
* Authenticates a user using their username and password, and retrieves user's details
|
|
31
31
|
*
|
|
@@ -34,7 +34,7 @@ export declare class AuthService<TKey, TUser extends UserDto<TKey> = UserDto<TKe
|
|
|
34
34
|
* @return {Promise<TUser>} Currently logged in user's details
|
|
35
35
|
* @throws {Error} Error if fetch fails
|
|
36
36
|
*/
|
|
37
|
-
signin(username: string, password: string): Promise<TUser
|
|
37
|
+
signin(username: string, password: string): Promise<ApiSuccessResponse<TUser, EmptyMetadata>>;
|
|
38
38
|
/**
|
|
39
39
|
* Deauthenticates current user
|
|
40
40
|
*
|
|
@@ -46,5 +46,5 @@ export declare class AuthService<TKey, TUser extends UserDto<TKey> = UserDto<TKe
|
|
|
46
46
|
* If any API response returns an "Unauthenticated" response, call this method
|
|
47
47
|
* to update local authentication state to unauthenticated
|
|
48
48
|
*/
|
|
49
|
-
|
|
49
|
+
_handleNoAuthApiResponse(): void;
|
|
50
50
|
}
|
|
@@ -30,21 +30,24 @@ export class AuthService {
|
|
|
30
30
|
async whoAmI() {
|
|
31
31
|
try {
|
|
32
32
|
const url = await apiInitializationService.getApiUrl('/auth/whoami');
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
else if (response.status === 401) {
|
|
39
|
-
return (this.user = undefined);
|
|
33
|
+
const res = await fetch(url, { credentials: 'include' });
|
|
34
|
+
if (!res.ok && res.status !== 401) {
|
|
35
|
+
this.user = undefined;
|
|
36
|
+
throw undefined;
|
|
40
37
|
}
|
|
41
|
-
|
|
38
|
+
if (!res.ok && res.status === 401) {
|
|
42
39
|
this.user = undefined;
|
|
43
|
-
|
|
40
|
+
return { result: this.user, metadata: {} };
|
|
44
41
|
}
|
|
42
|
+
const { success, result, metadata, error } = (await res.json());
|
|
43
|
+
if (!success)
|
|
44
|
+
throw new Error(error.message);
|
|
45
|
+
this.user = result;
|
|
46
|
+
return { result: this.user, metadata };
|
|
45
47
|
}
|
|
46
|
-
catch (
|
|
47
|
-
|
|
48
|
+
catch (err) {
|
|
49
|
+
// TODO: Extract error from well-formed response
|
|
50
|
+
throw err instanceof Error ? err : new Error('Failed checking authentication status');
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
53
|
/**
|
|
@@ -58,27 +61,24 @@ export class AuthService {
|
|
|
58
61
|
async signin(username, password) {
|
|
59
62
|
try {
|
|
60
63
|
const url = await apiInitializationService.getApiUrl('/auth/signin');
|
|
61
|
-
const
|
|
64
|
+
const res = await fetch(url, {
|
|
62
65
|
method: 'POST',
|
|
63
66
|
headers: { 'Content-Type': 'application/json' },
|
|
64
67
|
body: JSON.stringify({ username, password }),
|
|
65
68
|
credentials: 'include',
|
|
66
69
|
});
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
throw new Error('Failed signing in');
|
|
78
|
-
}
|
|
70
|
+
if (!res.ok)
|
|
71
|
+
throw undefined;
|
|
72
|
+
// TODO: Handle tokens if not using cookies
|
|
73
|
+
const { result, metadata } = await this.whoAmI();
|
|
74
|
+
if (result === undefined)
|
|
75
|
+
throw undefined;
|
|
76
|
+
this.user = result;
|
|
77
|
+
return { result: this.user, metadata };
|
|
79
78
|
}
|
|
80
|
-
catch (
|
|
81
|
-
|
|
79
|
+
catch (err) {
|
|
80
|
+
// TODO: Extract error from well-formed response
|
|
81
|
+
throw err instanceof Error ? err : new Error('Failed signing in');
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
@@ -90,24 +90,22 @@ export class AuthService {
|
|
|
90
90
|
async signout() {
|
|
91
91
|
try {
|
|
92
92
|
const url = await apiInitializationService.getApiUrl('/auth/signout');
|
|
93
|
-
const
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
else {
|
|
99
|
-
throw new Error('Failed signing out');
|
|
100
|
-
}
|
|
93
|
+
const res = await fetch(url, { credentials: 'include' });
|
|
94
|
+
if (!res.ok)
|
|
95
|
+
throw undefined;
|
|
96
|
+
this.user = undefined;
|
|
97
|
+
return;
|
|
101
98
|
}
|
|
102
|
-
catch (
|
|
103
|
-
|
|
99
|
+
catch (err) {
|
|
100
|
+
// TODO: Extract error from well-formed response
|
|
101
|
+
throw err instanceof Error ? err : new Error('Failed signing out');
|
|
104
102
|
}
|
|
105
103
|
}
|
|
106
104
|
/**
|
|
107
105
|
* If any API response returns an "Unauthenticated" response, call this method
|
|
108
106
|
* to update local authentication state to unauthenticated
|
|
109
107
|
*/
|
|
110
|
-
|
|
108
|
+
_handleNoAuthApiResponse() {
|
|
111
109
|
this.user = undefined;
|
|
112
110
|
}
|
|
113
111
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RoleDto } from '../../../../data';
|
|
1
|
+
import { ApiSuccessResponse, EmptyMetadata, ReadMetadata, RoleDto } from '../../../../data';
|
|
2
2
|
/**
|
|
3
3
|
* Client for authorization management operations
|
|
4
4
|
*
|
|
@@ -17,19 +17,19 @@ export declare class AuthorizationManagementControllerClient {
|
|
|
17
17
|
* @param includeClaims - Whether to include claims in the response
|
|
18
18
|
* @returns List of all roles
|
|
19
19
|
*/
|
|
20
|
-
getAllRoles(includeClaims: boolean): Promise<RoleDto[]
|
|
21
|
-
/**
|
|
22
|
-
* Creates or updates a role
|
|
23
|
-
* @param roleDto - The role to create or update
|
|
24
|
-
* @returns The created or updated role
|
|
25
|
-
*/
|
|
26
|
-
upsertRole(roleDto: RoleDto): Promise<RoleDto>;
|
|
20
|
+
getAllRoles(includeClaims: boolean): Promise<ApiSuccessResponse<RoleDto[], ReadMetadata>>;
|
|
27
21
|
/**
|
|
28
22
|
* Gets a role with its claims
|
|
29
23
|
* @param roleName - The name of the role
|
|
30
24
|
* @returns The role with its claims
|
|
31
25
|
*/
|
|
32
|
-
getRoleWithClaims(roleName: string): Promise<RoleDto
|
|
26
|
+
getRoleWithClaims(roleName: string): Promise<ApiSuccessResponse<RoleDto, ReadMetadata>>;
|
|
27
|
+
/**
|
|
28
|
+
* Creates or updates a role
|
|
29
|
+
* @param roleDto - The role to create or update
|
|
30
|
+
* @returns The created or updated role
|
|
31
|
+
*/
|
|
32
|
+
upsertRole(roleDto: RoleDto): Promise<ApiSuccessResponse<RoleDto, EmptyMetadata>>;
|
|
33
33
|
/**
|
|
34
34
|
* Deletes a role
|
|
35
35
|
* @param roleName - The name of the role to delete
|
|
@@ -22,17 +22,44 @@ export class AuthorizationManagementControllerClient {
|
|
|
22
22
|
async getAllRoles(includeClaims) {
|
|
23
23
|
try {
|
|
24
24
|
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/GetAllRoles?includeClaims=${includeClaims}`);
|
|
25
|
-
const
|
|
25
|
+
const res = await fetch(url, {
|
|
26
26
|
credentials: 'include',
|
|
27
27
|
});
|
|
28
|
-
if (!
|
|
29
|
-
throw
|
|
30
|
-
|
|
28
|
+
if (!res.ok)
|
|
29
|
+
throw undefined;
|
|
30
|
+
const { success, result, metadata, error } = (await res.json());
|
|
31
|
+
if (!success)
|
|
32
|
+
throw new Error(error.message);
|
|
33
|
+
return { result, metadata };
|
|
31
34
|
}
|
|
32
35
|
catch (err) {
|
|
36
|
+
// TODO: Extract error from well-formed response
|
|
33
37
|
throw err instanceof Error ? err : new Error('Unknown error fetching all roles');
|
|
34
38
|
}
|
|
35
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Gets a role with its claims
|
|
42
|
+
* @param roleName - The name of the role
|
|
43
|
+
* @returns The role with its claims
|
|
44
|
+
*/
|
|
45
|
+
async getRoleWithClaims(roleName) {
|
|
46
|
+
try {
|
|
47
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/GetRoleWithClaims/${encodeURIComponent(roleName)}`);
|
|
48
|
+
const res = await fetch(url, {
|
|
49
|
+
credentials: 'include',
|
|
50
|
+
});
|
|
51
|
+
if (!res.ok)
|
|
52
|
+
throw undefined;
|
|
53
|
+
const { success, result, metadata, error } = (await res.json());
|
|
54
|
+
if (!success)
|
|
55
|
+
throw new Error(error.message);
|
|
56
|
+
return { result, metadata };
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
// TODO: Extract error from well-formed response
|
|
60
|
+
throw err instanceof Error ? err : new Error('Unknown error fetching role with claims');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
36
63
|
/**
|
|
37
64
|
* Creates or updates a role
|
|
38
65
|
* @param roleDto - The role to create or update
|
|
@@ -41,7 +68,7 @@ export class AuthorizationManagementControllerClient {
|
|
|
41
68
|
async upsertRole(roleDto) {
|
|
42
69
|
try {
|
|
43
70
|
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/UpsertRole`);
|
|
44
|
-
const
|
|
71
|
+
const res = await fetch(url, {
|
|
45
72
|
method: 'PUT',
|
|
46
73
|
headers: {
|
|
47
74
|
'Content-Type': 'application/json',
|
|
@@ -49,35 +76,18 @@ export class AuthorizationManagementControllerClient {
|
|
|
49
76
|
body: JSON.stringify(roleDto),
|
|
50
77
|
credentials: 'include',
|
|
51
78
|
});
|
|
52
|
-
if (!
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
79
|
+
if (!res.ok)
|
|
80
|
+
throw undefined;
|
|
81
|
+
const { success, result, metadata, error } = (await res.json());
|
|
82
|
+
if (!success)
|
|
83
|
+
throw new Error(error.message);
|
|
84
|
+
return { result, metadata };
|
|
57
85
|
}
|
|
58
86
|
catch (err) {
|
|
87
|
+
// TODO: Extract error from well-formed response
|
|
59
88
|
throw err instanceof Error ? err : new Error('Unknown error upserting role');
|
|
60
89
|
}
|
|
61
90
|
}
|
|
62
|
-
/**
|
|
63
|
-
* Gets a role with its claims
|
|
64
|
-
* @param roleName - The name of the role
|
|
65
|
-
* @returns The role with its claims
|
|
66
|
-
*/
|
|
67
|
-
async getRoleWithClaims(roleName) {
|
|
68
|
-
try {
|
|
69
|
-
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/GetRoleWithClaims/${encodeURIComponent(roleName)}`);
|
|
70
|
-
const response = await fetch(url, {
|
|
71
|
-
credentials: 'include',
|
|
72
|
-
});
|
|
73
|
-
if (!response.ok)
|
|
74
|
-
throw new Error('Failed to fetch role with claims');
|
|
75
|
-
return response.json();
|
|
76
|
-
}
|
|
77
|
-
catch (err) {
|
|
78
|
-
throw err instanceof Error ? err : new Error('Unknown error fetching role with claims');
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
91
|
/**
|
|
82
92
|
* Deletes a role
|
|
83
93
|
* @param roleName - The name of the role to delete
|
|
@@ -90,12 +100,11 @@ export class AuthorizationManagementControllerClient {
|
|
|
90
100
|
method: 'DELETE',
|
|
91
101
|
credentials: 'include',
|
|
92
102
|
});
|
|
93
|
-
if (!response.ok)
|
|
94
|
-
|
|
95
|
-
throw new Error(errorText || 'Failed to delete role');
|
|
96
|
-
}
|
|
103
|
+
if (!response.ok)
|
|
104
|
+
throw undefined;
|
|
97
105
|
}
|
|
98
106
|
catch (err) {
|
|
107
|
+
// TODO: Extract error from well-formed response
|
|
99
108
|
throw err instanceof Error ? err : new Error('Unknown error deleting role');
|
|
100
109
|
}
|
|
101
110
|
}
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { ReadSelectedSearchPropertyDefinitionDto, ReadSelectedLogicalOperator } from '../..';
|
|
2
|
-
/**
|
|
3
|
-
* Search definition that supports property searches and nested groups.
|
|
4
|
-
*/
|
|
5
|
-
export type ReadSelectedSearchDefinitionDto = {
|
|
6
|
-
/**
|
|
7
|
-
* Logical operator (AND/OR) to combine search criteria.
|
|
8
|
-
*/
|
|
9
|
-
logicalOperator: ReadSelectedLogicalOperator;
|
|
10
|
-
/**
|
|
11
|
-
* Property-based search criteria.
|
|
12
|
-
*/
|
|
13
|
-
propertyCriteria?: ReadSelectedSearchPropertyDefinitionDto[];
|
|
14
|
-
/**
|
|
15
|
-
* Nested search definitions for complex queries.
|
|
16
|
-
*/
|
|
17
|
-
nestedSearchCriteria?: ReadSelectedSearchDefinitionDto[];
|
|
18
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type for entities that can, but don't have to have an Id property.
|
|
3
|
-
* If present, will be used as a primary key in the database, and if not it signifies an entity that was not yet
|
|
4
|
-
* stored.
|
|
5
|
-
*/
|
|
6
|
-
export type IOptionallyIdentifiable<TKey> = {
|
|
7
|
-
/**
|
|
8
|
-
* Gets or sets the Id of the entity.
|
|
9
|
-
*/
|
|
10
|
-
id?: TKey;
|
|
11
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/data/api/dto/{ReadSelectedSearchDefinitionDto.js → read/ReadSelectedSearchDefinitionDto.js}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/data/api/{interface/IOptionallyIdentifiable.js → dto/response/ApiSuccessResponse.js}
RENAMED
|
File without changes
|
/package/data/api/enum/{ReadSelectedLogicalOperator.d.ts → read/ReadSelectedLogicalOperator.d.ts}
RENAMED
|
File without changes
|
/package/data/api/enum/{ReadSelectedLogicalOperator.js → read/ReadSelectedLogicalOperator.js}
RENAMED
|
File without changes
|
|
File without changes
|
/package/data/api/enum/{ReadSelectedOrderingDirection.js → read/ReadSelectedOrderingDirection.js}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|