academe-kit 0.1.7 → 0.1.9
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/dist/index.d.ts +89 -8
- package/dist/index.esm.js +222 -34
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +220 -31
- package/dist/index.js.map +1 -1
- package/dist/types/components/ProtectedApp/index.d.ts +1 -1
- package/dist/types/context/SecurityProvider/types.d.ts +8 -5
- package/dist/types/hooks/useCurrentUser.d.ts +82 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/services/userService.d.ts +79 -0
- package/package.json +1 -1
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
import { KeycloakLoginOptions, KeycloakPromise } from 'keycloak-js';
|
|
2
|
+
import { MongoDBUser } from '../../services/userService';
|
|
2
3
|
export type AcademeKeycloakContextProps = {
|
|
3
4
|
realm: string;
|
|
4
5
|
hubUrl: string;
|
|
5
6
|
clientId: string;
|
|
6
7
|
keycloakUrl: string;
|
|
8
|
+
apiBaseUrl?: string;
|
|
7
9
|
children: React.ReactElement;
|
|
8
10
|
};
|
|
9
11
|
export type SecurityProviderProps = {
|
|
10
12
|
hubUrl: string;
|
|
13
|
+
apiBaseUrl?: string;
|
|
11
14
|
children: React.ReactElement;
|
|
12
15
|
};
|
|
13
16
|
export type KeycloakUser = {
|
|
14
17
|
name: string;
|
|
15
18
|
lastName: string;
|
|
16
19
|
email: string;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
};
|
|
21
|
+
export type AcademeUser = MongoDBUser & {
|
|
22
|
+
keycloakUser?: KeycloakUser;
|
|
20
23
|
};
|
|
21
24
|
export type SecurityContextType = {
|
|
22
25
|
isInitialized: boolean;
|
|
23
26
|
isAuthenticated: () => boolean;
|
|
24
27
|
signOut: () => void | null;
|
|
25
|
-
redirectToHub: (errorMessage: string) => void | null;
|
|
26
28
|
goToLogin: (options?: KeycloakLoginOptions | undefined) => KeycloakPromise<void, void> | null;
|
|
27
|
-
|
|
29
|
+
user: AcademeUser | null;
|
|
30
|
+
refreshUserData: () => Promise<void>;
|
|
28
31
|
hasRealmRole: (role: string) => boolean;
|
|
29
32
|
hasSchool: (schoolId: string) => boolean;
|
|
30
33
|
hasClientRole: (role: string, resource?: string) => boolean;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom hook for accessing current user data
|
|
3
|
+
* Provides easy access to MongoDB-enriched user information
|
|
4
|
+
*/
|
|
5
|
+
import { AcademeUser } from '../context/SecurityProvider/types';
|
|
6
|
+
export interface UseCurrentUserReturn {
|
|
7
|
+
user: AcademeUser | null;
|
|
8
|
+
isLoading: boolean;
|
|
9
|
+
error: Error | null;
|
|
10
|
+
userId: string | undefined;
|
|
11
|
+
email: string | undefined;
|
|
12
|
+
fullName: string | undefined;
|
|
13
|
+
schoolId: string | undefined;
|
|
14
|
+
roles: string[];
|
|
15
|
+
isStudent: boolean;
|
|
16
|
+
registrationNumber: string | undefined;
|
|
17
|
+
className: string | undefined;
|
|
18
|
+
completionRate: number;
|
|
19
|
+
engagementRate: number;
|
|
20
|
+
isAdmin: boolean;
|
|
21
|
+
isSchoolAdmin: boolean;
|
|
22
|
+
isTeacher: boolean;
|
|
23
|
+
hasCompletedOnboarding: boolean;
|
|
24
|
+
hasAccessEnabled: boolean;
|
|
25
|
+
refreshUser: () => Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
export declare const useCurrentUser: () => UseCurrentUserReturn;
|
|
28
|
+
/**
|
|
29
|
+
* Hook to check if user has a specific role
|
|
30
|
+
*/
|
|
31
|
+
export declare const useHasRole: (role: string) => boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Hook to check if user has any of the specified roles
|
|
34
|
+
*/
|
|
35
|
+
export declare const useHasAnyRole: (requiredRoles: string[]) => boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Hook to check if user has all of the specified roles
|
|
38
|
+
*/
|
|
39
|
+
export declare const useHasAllRoles: (requiredRoles: string[]) => boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Hook to check if user belongs to a specific school
|
|
42
|
+
*/
|
|
43
|
+
export declare const useHasSchoolAccess: (schoolId: string) => boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Hook for student-specific data and checks
|
|
46
|
+
*/
|
|
47
|
+
export declare const useStudentData: () => {
|
|
48
|
+
isStudent: boolean;
|
|
49
|
+
hasStudentData: boolean;
|
|
50
|
+
studentInfo: null;
|
|
51
|
+
academicInfo: null;
|
|
52
|
+
responsibleInfo: null;
|
|
53
|
+
metrics: null;
|
|
54
|
+
} | {
|
|
55
|
+
isStudent: boolean;
|
|
56
|
+
hasStudentData: boolean;
|
|
57
|
+
studentInfo: {
|
|
58
|
+
registrationNumber: string | undefined;
|
|
59
|
+
cpf: string | undefined;
|
|
60
|
+
birthDate: string | undefined;
|
|
61
|
+
gender: string | undefined;
|
|
62
|
+
phone: string | undefined;
|
|
63
|
+
};
|
|
64
|
+
academicInfo: {
|
|
65
|
+
schoolYear: string | undefined;
|
|
66
|
+
grade: string | undefined;
|
|
67
|
+
className: string | undefined;
|
|
68
|
+
shift: string | undefined;
|
|
69
|
+
classId: string | undefined;
|
|
70
|
+
};
|
|
71
|
+
responsibleInfo: {
|
|
72
|
+
name: string | undefined;
|
|
73
|
+
email: string | undefined;
|
|
74
|
+
phone: string | undefined;
|
|
75
|
+
};
|
|
76
|
+
metrics: {
|
|
77
|
+
completionRate: number;
|
|
78
|
+
engagementRate: number;
|
|
79
|
+
hasCompletedOnboarding: boolean;
|
|
80
|
+
hasAccessEnabled: boolean;
|
|
81
|
+
};
|
|
82
|
+
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -5,7 +5,9 @@ export { ProtectedComponent } from './components/ProtectedComponent';
|
|
|
5
5
|
export { ProtectedRouter } from './components/ProtectedRouter';
|
|
6
6
|
export { Spinner } from './components/ui/spinner';
|
|
7
7
|
export { AcademeAuthProvider, useAcademeAuth } from './context/SecurityProvider';
|
|
8
|
-
export
|
|
8
|
+
export { createUserService } from './services/userService';
|
|
9
|
+
export type { MongoDBUser, UserServiceConfig } from './services/userService';
|
|
10
|
+
export type { AcademeKeycloakContextProps, SecurityProviderProps, KeycloakUser, SecurityContextType, AcademeUser, } from './context/SecurityProvider/types';
|
|
9
11
|
export { cn } from './lib/utils';
|
|
10
12
|
import './index.css';
|
|
11
13
|
import './styles/globals.css';
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User Service - Fetches complete user data from MongoDB
|
|
3
|
+
* This service interacts with the new unified users collection
|
|
4
|
+
*/
|
|
5
|
+
export interface MongoDBUser {
|
|
6
|
+
id: string;
|
|
7
|
+
keycloak_user_id: string;
|
|
8
|
+
email: string;
|
|
9
|
+
full_name: string;
|
|
10
|
+
phone?: string;
|
|
11
|
+
school_id?: string;
|
|
12
|
+
active: boolean;
|
|
13
|
+
created_at: string;
|
|
14
|
+
updated_at: string;
|
|
15
|
+
last_login?: string;
|
|
16
|
+
registration_number?: string;
|
|
17
|
+
school_year?: string;
|
|
18
|
+
serie_ano?: string;
|
|
19
|
+
turma?: string;
|
|
20
|
+
turno?: string;
|
|
21
|
+
class_id?: string;
|
|
22
|
+
nome_responsavel?: string;
|
|
23
|
+
email_responsavel?: string;
|
|
24
|
+
telefone_responsavel?: string;
|
|
25
|
+
data_nascimento?: string;
|
|
26
|
+
cpf?: string;
|
|
27
|
+
sexo?: string;
|
|
28
|
+
completion_rate: number;
|
|
29
|
+
engagement_rate: number;
|
|
30
|
+
onboarding_completo: boolean;
|
|
31
|
+
acesso_liberado: boolean;
|
|
32
|
+
roles?: string[];
|
|
33
|
+
}
|
|
34
|
+
export interface UserServiceConfig {
|
|
35
|
+
apiBaseUrl: string;
|
|
36
|
+
getAccessToken: () => string | null;
|
|
37
|
+
}
|
|
38
|
+
declare class UserService {
|
|
39
|
+
private client;
|
|
40
|
+
private getAccessToken;
|
|
41
|
+
private cachedUser;
|
|
42
|
+
private cacheExpiry;
|
|
43
|
+
constructor(config: UserServiceConfig);
|
|
44
|
+
/**
|
|
45
|
+
* Get current user data from MongoDB
|
|
46
|
+
* Includes caching to reduce API calls
|
|
47
|
+
*/
|
|
48
|
+
getCurrentUser(forceRefresh?: boolean): Promise<MongoDBUser | null>;
|
|
49
|
+
/**
|
|
50
|
+
* Update current user data
|
|
51
|
+
*/
|
|
52
|
+
updateCurrentUser(data: Partial<MongoDBUser>): Promise<MongoDBUser | null>;
|
|
53
|
+
/**
|
|
54
|
+
* Clear cached user data
|
|
55
|
+
*/
|
|
56
|
+
clearCache(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Check if user has a specific role
|
|
59
|
+
*/
|
|
60
|
+
hasRole(user: MongoDBUser | null, role: string): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Check if user has access to a specific school
|
|
63
|
+
*/
|
|
64
|
+
hasSchoolAccess(user: MongoDBUser | null, schoolId: string): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Check if user is a student (has student-specific data)
|
|
67
|
+
*/
|
|
68
|
+
isStudent(user: MongoDBUser | null): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Check if user has completed onboarding
|
|
71
|
+
*/
|
|
72
|
+
hasCompletedOnboarding(user: MongoDBUser | null): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Check if user has access enabled
|
|
75
|
+
*/
|
|
76
|
+
hasAccessEnabled(user: MongoDBUser | null): boolean;
|
|
77
|
+
}
|
|
78
|
+
export declare const createUserService: (config: UserServiceConfig) => UserService;
|
|
79
|
+
export default UserService;
|