@intellegens/cornerstone-client 0.0.17 → 0.0.19
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/auth/Role/index.d.ts +8 -0
- package/data/auth/Role/index.js +1 -0
- package/data/auth/User/index.d.ts +4 -1
- package/data/auth/index.d.ts +1 -0
- package/data/auth/index.js +1 -0
- package/package.json +4 -2
- package/services/api/{client/ApiCrudControllerClient → ApiCrudControllerClient}/index.d.ts +1 -1
- package/services/api/{client/ApiCrudControllerClient → ApiCrudControllerClient}/index.js +1 -1
- package/services/api/{client/ApiReadControllerClient → ApiReadControllerClient}/index.d.ts +1 -1
- package/services/api/{client/ApiReadControllerClient → ApiReadControllerClient}/index.js +1 -1
- package/services/api/UserManagementControllerClient/index.d.ts +35 -0
- package/services/api/UserManagementControllerClient/index.js +93 -0
- package/services/api/index.d.ts +4 -2
- package/services/api/index.js +4 -2
- package/services/auth/client/AuthService/index.d.ts +50 -0
- package/services/auth/client/AuthService/index.js +113 -0
- package/services/auth/client/AuthorizationManagementControllerClient/index.d.ts +39 -0
- package/services/auth/client/AuthorizationManagementControllerClient/index.js +102 -0
- package/services/auth/client/index.d.ts +2 -0
- package/services/auth/client/index.js +2 -0
- package/services/auth/index.d.ts +1 -50
- package/services/auth/index.js +1 -113
- package/services/api/client/index.d.ts +0 -2
- package/services/api/client/index.js +0 -2
- /package/services/api/{initialization → ApiInitializationService}/index.d.ts +0 -0
- /package/services/api/{initialization → ApiInitializationService}/index.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Claim } from "../../../data";
|
|
1
2
|
/**
|
|
2
3
|
* Represents a user with an identifier and email address.
|
|
3
4
|
*
|
|
@@ -5,8 +6,10 @@
|
|
|
5
6
|
*
|
|
6
7
|
* @param {TId} id The unique identifier for the user.
|
|
7
8
|
* @param {string} email The email address associated with the user.
|
|
9
|
+
* @param {Claim[]} claims The claims associated with the user.
|
|
8
10
|
*/
|
|
9
11
|
export type User<TId> = {
|
|
10
|
-
id: TId;
|
|
12
|
+
id: TId | undefined;
|
|
11
13
|
email: string;
|
|
14
|
+
claims: Claim[];
|
|
12
15
|
};
|
package/data/auth/index.d.ts
CHANGED
package/data/auth/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intellegens/cornerstone-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
|
+
"clean": "node -e \"require('fs-extra').emptyDir('./dist');\"",
|
|
7
8
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
-
"build": "npm run transpile-types && tsc && tsc-alias",
|
|
9
|
+
"build": "npm run clean && npm run transpile-types && tsc && tsc-alias",
|
|
9
10
|
"demo": "npm run build && npx vite build && npx tsx ./demo",
|
|
10
11
|
"transpile-types": "cd ../utils/cli && npm run cli zod-gen -- --input '../../client/src/data/_jsonschema' --output '../../client/src/data/_generated'"
|
|
11
12
|
},
|
|
@@ -19,6 +20,7 @@
|
|
|
19
20
|
"eslint": "^9.21.0",
|
|
20
21
|
"eslint-config-prettier": "^10.0.1",
|
|
21
22
|
"express": "^4.21.2",
|
|
23
|
+
"fs-extra": "^11.3.0",
|
|
22
24
|
"globals": "^16.0.0",
|
|
23
25
|
"prettier": "^3.5.2",
|
|
24
26
|
"tsc-alias": "^1.8.11",
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ApiCrudControllerClient } from '../..';
|
|
2
|
+
/**
|
|
3
|
+
* Client for user management operations
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @class UserManagementControllerClient
|
|
7
|
+
* @template TKey - Type of the entity key (e.g., number, string, GUID, etc.)
|
|
8
|
+
* @template TDto - Data Transfer Object representing the user entity
|
|
9
|
+
*/
|
|
10
|
+
export declare class UserManagementControllerClient<TKey, TDto> extends ApiCrudControllerClient<TKey, TDto> {
|
|
11
|
+
/**
|
|
12
|
+
* Gets the roles assigned to a user
|
|
13
|
+
* @param id - The ID of the user
|
|
14
|
+
* @returns List of role names assigned to the user
|
|
15
|
+
*/
|
|
16
|
+
getUserRoles(id: TKey): Promise<string[]>;
|
|
17
|
+
/**
|
|
18
|
+
* Gets the claims assigned to a user
|
|
19
|
+
* @param id - The ID of the user
|
|
20
|
+
* @returns List of claims assigned to the user
|
|
21
|
+
*/
|
|
22
|
+
getUserClaims(id: TKey): Promise<Record<string, string>>;
|
|
23
|
+
/**
|
|
24
|
+
* Gets all available roles in the system
|
|
25
|
+
* @returns List of all role names
|
|
26
|
+
*/
|
|
27
|
+
getAllRoles(): Promise<string[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Changes the password for a user
|
|
30
|
+
* @param id - The ID of the user
|
|
31
|
+
* @param newPassword - The new password to set
|
|
32
|
+
* @returns Promise that resolves when the password is changed successfully
|
|
33
|
+
*/
|
|
34
|
+
changePassword(id: TKey, newPassword: string): Promise<void>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { ApiCrudControllerClient, apiInitializationService } from '../..';
|
|
2
|
+
/**
|
|
3
|
+
* Client for user management operations
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @class UserManagementControllerClient
|
|
7
|
+
* @template TKey - Type of the entity key (e.g., number, string, GUID, etc.)
|
|
8
|
+
* @template TDto - Data Transfer Object representing the user entity
|
|
9
|
+
*/
|
|
10
|
+
export class UserManagementControllerClient extends ApiCrudControllerClient {
|
|
11
|
+
/**
|
|
12
|
+
* Gets the roles assigned to a user
|
|
13
|
+
* @param id - The ID of the user
|
|
14
|
+
* @returns List of role names assigned to the user
|
|
15
|
+
*/
|
|
16
|
+
async getUserRoles(id) {
|
|
17
|
+
try {
|
|
18
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/GetUserRoles${encodeURIComponent(String(id))}`);
|
|
19
|
+
const response = await fetch(url, {
|
|
20
|
+
credentials: 'include',
|
|
21
|
+
});
|
|
22
|
+
if (!response.ok)
|
|
23
|
+
throw new Error('Failed to fetch user roles');
|
|
24
|
+
return response.json();
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
throw err instanceof Error ? err : new Error('Unknown error fetching user roles');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Gets the claims assigned to a user
|
|
32
|
+
* @param id - The ID of the user
|
|
33
|
+
* @returns List of claims assigned to the user
|
|
34
|
+
*/
|
|
35
|
+
async getUserClaims(id) {
|
|
36
|
+
try {
|
|
37
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/GetUserClaims/${encodeURIComponent(String(id))}`);
|
|
38
|
+
const response = await fetch(url, {
|
|
39
|
+
credentials: 'include',
|
|
40
|
+
});
|
|
41
|
+
if (!response.ok)
|
|
42
|
+
throw new Error('Failed to fetch user claims');
|
|
43
|
+
return response.json();
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
throw err instanceof Error ? err : new Error('Unknown error fetching user claims');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Gets all available roles in the system
|
|
51
|
+
* @returns List of all role names
|
|
52
|
+
*/
|
|
53
|
+
async getAllRoles() {
|
|
54
|
+
try {
|
|
55
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/GetAllRoles`);
|
|
56
|
+
const response = await fetch(url, {
|
|
57
|
+
credentials: 'include',
|
|
58
|
+
});
|
|
59
|
+
if (!response.ok)
|
|
60
|
+
throw new Error('Failed to fetch all roles');
|
|
61
|
+
return response.json();
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
throw err instanceof Error ? err : new Error('Unknown error fetching all roles');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Changes the password for a user
|
|
69
|
+
* @param id - The ID of the user
|
|
70
|
+
* @param newPassword - The new password to set
|
|
71
|
+
* @returns Promise that resolves when the password is changed successfully
|
|
72
|
+
*/
|
|
73
|
+
async changePassword(id, newPassword) {
|
|
74
|
+
try {
|
|
75
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/ChangePassword/${encodeURIComponent(String(id))}`);
|
|
76
|
+
const response = await fetch(url, {
|
|
77
|
+
method: 'POST',
|
|
78
|
+
headers: {
|
|
79
|
+
'Content-Type': 'application/json'
|
|
80
|
+
},
|
|
81
|
+
body: JSON.stringify(newPassword),
|
|
82
|
+
credentials: 'include',
|
|
83
|
+
});
|
|
84
|
+
if (!response.ok) {
|
|
85
|
+
const errorText = await response.text();
|
|
86
|
+
throw new Error(errorText || 'Failed to change password');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
throw err instanceof Error ? err : new Error('Unknown error changing password');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
package/services/api/index.d.ts
CHANGED
package/services/api/index.js
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { User, UserInfo } from '../../../../data';
|
|
2
|
+
export { User, UserInfo };
|
|
3
|
+
/**
|
|
4
|
+
* AuthService class is responsible for managing user authentication operations.
|
|
5
|
+
* It supports login, logout, and checking the current user's details.
|
|
6
|
+
*
|
|
7
|
+
* @export
|
|
8
|
+
* @class AuthService
|
|
9
|
+
*/
|
|
10
|
+
export declare class AuthService<TId, TUser extends User<TId> = User<TId>> {
|
|
11
|
+
/**
|
|
12
|
+
* Holds currently authenticated user's details
|
|
13
|
+
*/
|
|
14
|
+
user: TUser | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Initializes the Authentication status by checking with the API if the current user is authenticated or not
|
|
17
|
+
*
|
|
18
|
+
* @async
|
|
19
|
+
* @return {Promise<void>} Resolves when initialization is complete.
|
|
20
|
+
*/
|
|
21
|
+
initialize(): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Checks if user is authenticated and retrieves the current user's details if they are
|
|
24
|
+
*
|
|
25
|
+
* @return {Promise<TUser>} Currently logged in user's details
|
|
26
|
+
* @throws {Error} Error if fetch fails
|
|
27
|
+
*/
|
|
28
|
+
whoAmI(): Promise<TUser | undefined>;
|
|
29
|
+
/**
|
|
30
|
+
* Authenticates a user using their username and password, and retrieves user's details
|
|
31
|
+
*
|
|
32
|
+
* @param {string} username Login credentials: username
|
|
33
|
+
* @param {string} password Login credentials: password
|
|
34
|
+
* @return {Promise<TUser>} Currently logged in user's details
|
|
35
|
+
* @throws {Error} Error if fetch fails
|
|
36
|
+
*/
|
|
37
|
+
signin(username: string, password: string): Promise<TUser>;
|
|
38
|
+
/**
|
|
39
|
+
* Deauthenticates current user
|
|
40
|
+
*
|
|
41
|
+
* @return {Promise<void>}
|
|
42
|
+
* @throws {Error} Error if fetch fails
|
|
43
|
+
*/
|
|
44
|
+
signout(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* If any API response returns an "Unauthenticated" response, call this method
|
|
47
|
+
* to update local authentication state to unauthenticated
|
|
48
|
+
*/
|
|
49
|
+
_handleResponse401(): void;
|
|
50
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { apiInitializationService } from '../../..';
|
|
2
|
+
/**
|
|
3
|
+
* AuthService class is responsible for managing user authentication operations.
|
|
4
|
+
* It supports login, logout, and checking the current user's details.
|
|
5
|
+
*
|
|
6
|
+
* @export
|
|
7
|
+
* @class AuthService
|
|
8
|
+
*/
|
|
9
|
+
export class AuthService {
|
|
10
|
+
/**
|
|
11
|
+
* Holds currently authenticated user's details
|
|
12
|
+
*/
|
|
13
|
+
user = undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Initializes the Authentication status by checking with the API if the current user is authenticated or not
|
|
16
|
+
*
|
|
17
|
+
* @async
|
|
18
|
+
* @return {Promise<void>} Resolves when initialization is complete.
|
|
19
|
+
*/
|
|
20
|
+
async initialize() {
|
|
21
|
+
// Check user's authentication status
|
|
22
|
+
await this.whoAmI();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Checks if user is authenticated and retrieves the current user's details if they are
|
|
26
|
+
*
|
|
27
|
+
* @return {Promise<TUser>} Currently logged in user's details
|
|
28
|
+
* @throws {Error} Error if fetch fails
|
|
29
|
+
*/
|
|
30
|
+
async whoAmI() {
|
|
31
|
+
try {
|
|
32
|
+
const url = await apiInitializationService.getApiUrl('/auth/whoami');
|
|
33
|
+
const response = await fetch(url, { credentials: 'include' });
|
|
34
|
+
if (response.ok) {
|
|
35
|
+
const info = await response.json();
|
|
36
|
+
return (this.user = info.user);
|
|
37
|
+
}
|
|
38
|
+
else if (response.status === 401) {
|
|
39
|
+
return (this.user = undefined);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this.user = undefined;
|
|
43
|
+
throw new Error('Failed checking authentication status');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
throw error instanceof Error ? error : new Error('Failed checking authentication status');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Authenticates a user using their username and password, and retrieves user's details
|
|
52
|
+
*
|
|
53
|
+
* @param {string} username Login credentials: username
|
|
54
|
+
* @param {string} password Login credentials: password
|
|
55
|
+
* @return {Promise<TUser>} Currently logged in user's details
|
|
56
|
+
* @throws {Error} Error if fetch fails
|
|
57
|
+
*/
|
|
58
|
+
async signin(username, password) {
|
|
59
|
+
try {
|
|
60
|
+
const url = await apiInitializationService.getApiUrl('/auth/signin');
|
|
61
|
+
const response = await fetch(url, {
|
|
62
|
+
method: 'POST',
|
|
63
|
+
headers: { 'Content-Type': 'application/json' },
|
|
64
|
+
body: JSON.stringify({ username, password }),
|
|
65
|
+
credentials: 'include',
|
|
66
|
+
});
|
|
67
|
+
if (response.ok) {
|
|
68
|
+
const user = await this.whoAmI();
|
|
69
|
+
if (user !== undefined) {
|
|
70
|
+
return (this.user = user);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
throw new Error('Failed signing in');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
throw new Error('Failed signing in');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
throw error instanceof Error ? error : new Error('Failed signing in');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Deauthenticates current user
|
|
86
|
+
*
|
|
87
|
+
* @return {Promise<void>}
|
|
88
|
+
* @throws {Error} Error if fetch fails
|
|
89
|
+
*/
|
|
90
|
+
async signout() {
|
|
91
|
+
try {
|
|
92
|
+
const url = await apiInitializationService.getApiUrl('/auth/signout');
|
|
93
|
+
const response = await fetch(url, { credentials: 'include' });
|
|
94
|
+
if (response.ok) {
|
|
95
|
+
this.user = undefined;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
throw new Error('Failed signing out');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
throw error instanceof Error ? error : new Error('Failed signing out');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* If any API response returns an "Unauthenticated" response, call this method
|
|
108
|
+
* to update local authentication state to unauthenticated
|
|
109
|
+
*/
|
|
110
|
+
_handleResponse401() {
|
|
111
|
+
this.user = undefined;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Role } from '../../../../data';
|
|
2
|
+
/**
|
|
3
|
+
* Client for authorization management operations
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @class AuthorizationManagementControllerClient
|
|
7
|
+
*/
|
|
8
|
+
export declare class AuthorizationManagementControllerClient {
|
|
9
|
+
protected readonly baseControllerPath: string;
|
|
10
|
+
/**
|
|
11
|
+
* Constructor
|
|
12
|
+
* @param baseControllerPath Base path to API controller
|
|
13
|
+
*/
|
|
14
|
+
constructor(baseControllerPath?: string);
|
|
15
|
+
/**
|
|
16
|
+
* Gets all roles in the system
|
|
17
|
+
* @param includeClaims - Whether to include claims in the response
|
|
18
|
+
* @returns List of all roles
|
|
19
|
+
*/
|
|
20
|
+
getAllRoles(includeClaims: boolean): Promise<Role[]>;
|
|
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: Role): Promise<Role>;
|
|
27
|
+
/**
|
|
28
|
+
* Gets a role with its claims
|
|
29
|
+
* @param roleName - The name of the role
|
|
30
|
+
* @returns The role with its claims
|
|
31
|
+
*/
|
|
32
|
+
getRoleWithClaims(roleName: string): Promise<Role>;
|
|
33
|
+
/**
|
|
34
|
+
* Deletes a role
|
|
35
|
+
* @param roleName - The name of the role to delete
|
|
36
|
+
* @returns Promise that resolves when the role is deleted successfully
|
|
37
|
+
*/
|
|
38
|
+
deleteRole(roleName: string): Promise<void>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { apiInitializationService } from '../../..';
|
|
2
|
+
/**
|
|
3
|
+
* Client for authorization management operations
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @class AuthorizationManagementControllerClient
|
|
7
|
+
*/
|
|
8
|
+
export class AuthorizationManagementControllerClient {
|
|
9
|
+
baseControllerPath;
|
|
10
|
+
/**
|
|
11
|
+
* Constructor
|
|
12
|
+
* @param baseControllerPath Base path to API controller
|
|
13
|
+
*/
|
|
14
|
+
constructor(baseControllerPath = 'AuthorizationManagement') {
|
|
15
|
+
this.baseControllerPath = baseControllerPath;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Gets all roles in the system
|
|
19
|
+
* @param includeClaims - Whether to include claims in the response
|
|
20
|
+
* @returns List of all roles
|
|
21
|
+
*/
|
|
22
|
+
async getAllRoles(includeClaims) {
|
|
23
|
+
try {
|
|
24
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/GetAllRoles?includeClaims=${includeClaims}`);
|
|
25
|
+
const response = await fetch(url, {
|
|
26
|
+
credentials: 'include',
|
|
27
|
+
});
|
|
28
|
+
if (!response.ok)
|
|
29
|
+
throw new Error('Failed to fetch all roles');
|
|
30
|
+
return response.json();
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
throw err instanceof Error ? err : new Error('Unknown error fetching all roles');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Creates or updates a role
|
|
38
|
+
* @param roleDto - The role to create or update
|
|
39
|
+
* @returns The created or updated role
|
|
40
|
+
*/
|
|
41
|
+
async upsertRole(roleDto) {
|
|
42
|
+
try {
|
|
43
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/UpsertRole`);
|
|
44
|
+
const response = await fetch(url, {
|
|
45
|
+
method: 'PUT',
|
|
46
|
+
headers: {
|
|
47
|
+
'Content-Type': 'application/json'
|
|
48
|
+
},
|
|
49
|
+
body: JSON.stringify(roleDto),
|
|
50
|
+
credentials: 'include',
|
|
51
|
+
});
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
const errorText = await response.text();
|
|
54
|
+
throw new Error(errorText || 'Failed to upsert role');
|
|
55
|
+
}
|
|
56
|
+
return response.json();
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
throw err instanceof Error ? err : new Error('Unknown error upserting role');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
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
|
+
/**
|
|
82
|
+
* Deletes a role
|
|
83
|
+
* @param roleName - The name of the role to delete
|
|
84
|
+
* @returns Promise that resolves when the role is deleted successfully
|
|
85
|
+
*/
|
|
86
|
+
async deleteRole(roleName) {
|
|
87
|
+
try {
|
|
88
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/DeleteRole/${encodeURIComponent(roleName)}`);
|
|
89
|
+
const response = await fetch(url, {
|
|
90
|
+
method: 'DELETE',
|
|
91
|
+
credentials: 'include',
|
|
92
|
+
});
|
|
93
|
+
if (!response.ok) {
|
|
94
|
+
const errorText = await response.text();
|
|
95
|
+
throw new Error(errorText || 'Failed to delete role');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
throw err instanceof Error ? err : new Error('Unknown error deleting role');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
package/services/auth/index.d.ts
CHANGED
|
@@ -1,50 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { User, UserInfo };
|
|
3
|
-
/**
|
|
4
|
-
* AuthService class is responsible for managing user authentication operations.
|
|
5
|
-
* It supports login, logout, and checking the current user's details.
|
|
6
|
-
*
|
|
7
|
-
* @export
|
|
8
|
-
* @class AuthService
|
|
9
|
-
*/
|
|
10
|
-
export declare class AuthService<TId, TUser = User<TId>> {
|
|
11
|
-
/**
|
|
12
|
-
* Holds currently authenticated user's details
|
|
13
|
-
*/
|
|
14
|
-
user: TUser | undefined;
|
|
15
|
-
/**
|
|
16
|
-
* Initializes the Authentication status by checking with the API if the current user is authenticated or not
|
|
17
|
-
*
|
|
18
|
-
* @async
|
|
19
|
-
* @return {Promise<void>} Resolves when initialization is complete.
|
|
20
|
-
*/
|
|
21
|
-
initialize(): Promise<void>;
|
|
22
|
-
/**
|
|
23
|
-
* Checks if user is authenticated and retrieves the current user's details if they are
|
|
24
|
-
*
|
|
25
|
-
* @return {Promise<TUser>} Currently logged in user's details
|
|
26
|
-
* @throws {Error} Error if fetch fails
|
|
27
|
-
*/
|
|
28
|
-
whoAmI(): Promise<TUser | undefined>;
|
|
29
|
-
/**
|
|
30
|
-
* Authenticates a user using their username and password, and retrieves user's details
|
|
31
|
-
*
|
|
32
|
-
* @param {string} username Login credentials: username
|
|
33
|
-
* @param {string} password Login credentials: password
|
|
34
|
-
* @return {Promise<TUser>} Currently logged in user's details
|
|
35
|
-
* @throws {Error} Error if fetch fails
|
|
36
|
-
*/
|
|
37
|
-
signin(username: string, password: string): Promise<TUser>;
|
|
38
|
-
/**
|
|
39
|
-
* Deauthenticates current user
|
|
40
|
-
*
|
|
41
|
-
* @return {Promise<void>}
|
|
42
|
-
* @throws {Error} Error if fetch fails
|
|
43
|
-
*/
|
|
44
|
-
signout(): Promise<void>;
|
|
45
|
-
/**
|
|
46
|
-
* If any API response returns an "Unauthenticated" response, call this method
|
|
47
|
-
* to update local authentication state to unauthenticated
|
|
48
|
-
*/
|
|
49
|
-
_handleResponse401(): void;
|
|
50
|
-
}
|
|
1
|
+
export * from './client';
|
package/services/auth/index.js
CHANGED
|
@@ -1,113 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* AuthService class is responsible for managing user authentication operations.
|
|
4
|
-
* It supports login, logout, and checking the current user's details.
|
|
5
|
-
*
|
|
6
|
-
* @export
|
|
7
|
-
* @class AuthService
|
|
8
|
-
*/
|
|
9
|
-
export class AuthService {
|
|
10
|
-
/**
|
|
11
|
-
* Holds currently authenticated user's details
|
|
12
|
-
*/
|
|
13
|
-
user = undefined;
|
|
14
|
-
/**
|
|
15
|
-
* Initializes the Authentication status by checking with the API if the current user is authenticated or not
|
|
16
|
-
*
|
|
17
|
-
* @async
|
|
18
|
-
* @return {Promise<void>} Resolves when initialization is complete.
|
|
19
|
-
*/
|
|
20
|
-
async initialize() {
|
|
21
|
-
// Check user's authentication status
|
|
22
|
-
await this.whoAmI();
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Checks if user is authenticated and retrieves the current user's details if they are
|
|
26
|
-
*
|
|
27
|
-
* @return {Promise<TUser>} Currently logged in user's details
|
|
28
|
-
* @throws {Error} Error if fetch fails
|
|
29
|
-
*/
|
|
30
|
-
async whoAmI() {
|
|
31
|
-
try {
|
|
32
|
-
const url = await apiInitializationService.getApiUrl('/auth/whoami');
|
|
33
|
-
const response = await fetch(url, { credentials: 'include' });
|
|
34
|
-
if (response.ok) {
|
|
35
|
-
const info = await response.json();
|
|
36
|
-
return (this.user = info.user);
|
|
37
|
-
}
|
|
38
|
-
else if (response.status === 401) {
|
|
39
|
-
return (this.user = undefined);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
this.user = undefined;
|
|
43
|
-
throw new Error('Failed checking authentication status');
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
throw error instanceof Error ? error : new Error('Failed checking authentication status');
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Authenticates a user using their username and password, and retrieves user's details
|
|
52
|
-
*
|
|
53
|
-
* @param {string} username Login credentials: username
|
|
54
|
-
* @param {string} password Login credentials: password
|
|
55
|
-
* @return {Promise<TUser>} Currently logged in user's details
|
|
56
|
-
* @throws {Error} Error if fetch fails
|
|
57
|
-
*/
|
|
58
|
-
async signin(username, password) {
|
|
59
|
-
try {
|
|
60
|
-
const url = await apiInitializationService.getApiUrl('/auth/signin');
|
|
61
|
-
const response = await fetch(url, {
|
|
62
|
-
method: 'POST',
|
|
63
|
-
headers: { 'Content-Type': 'application/json' },
|
|
64
|
-
body: JSON.stringify({ username, password }),
|
|
65
|
-
credentials: 'include',
|
|
66
|
-
});
|
|
67
|
-
if (response.ok) {
|
|
68
|
-
const user = await this.whoAmI();
|
|
69
|
-
if (user !== undefined) {
|
|
70
|
-
return (this.user = user);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
throw new Error('Failed signing in');
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
throw new Error('Failed signing in');
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
throw error instanceof Error ? error : new Error('Failed signing in');
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Deauthenticates current user
|
|
86
|
-
*
|
|
87
|
-
* @return {Promise<void>}
|
|
88
|
-
* @throws {Error} Error if fetch fails
|
|
89
|
-
*/
|
|
90
|
-
async signout() {
|
|
91
|
-
try {
|
|
92
|
-
const url = await apiInitializationService.getApiUrl('/auth/signout');
|
|
93
|
-
const response = await fetch(url, { credentials: 'include' });
|
|
94
|
-
if (response.ok) {
|
|
95
|
-
this.user = undefined;
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
throw new Error('Failed signing out');
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
throw error instanceof Error ? error : new Error('Failed signing out');
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* If any API response returns an "Unauthenticated" response, call this method
|
|
108
|
-
* to update local authentication state to unauthenticated
|
|
109
|
-
*/
|
|
110
|
-
_handleResponse401() {
|
|
111
|
-
this.user = undefined;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
1
|
+
export * from './client';
|
|
File without changes
|
|
File without changes
|