@mui-toolpad-extended-tuni/users 3.0.3 → 3.1.0

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/README.md CHANGED
@@ -5,14 +5,20 @@ Users microservice extension for MUI Toolpad Extended TUNI. This package provide
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @mui-toolpad-extended-tuni/users
8
+ npm install @mui-toolpad-extended-tuni/users @mui-toolpad-extended-tuni/main @mui-toolpad-extended-tuni/core
9
9
  ```
10
10
 
11
- **Note**: This package requires `mui-toolpad-extended-tuni@^3.0.0` as a peer dependency.
11
+ **Important**: You must also install `@mui-toolpad-extended-tuni/main` and `@mui-toolpad-extended-tuni/core` as they are required peer dependencies.
12
12
 
13
- ## Peer Dependencies
13
+ ## Required Peer Dependencies
14
14
 
15
- - `mui-toolpad-extended-tuni@^3.0.0`
15
+ This package requires the following peer dependencies to be installed:
16
+
17
+ ### Required Packages
18
+ - **`@mui-toolpad-extended-tuni/main`**: ^3.4.0 - **MUST be installed separately**
19
+ - **`@mui-toolpad-extended-tuni/core`**: ^3.2.0 - **MUST be installed separately** (also required by main)
20
+
21
+ ### React & UI Framework
16
22
  - `react@^19.0.0`
17
23
  - `react-dom@^19.0.0`
18
24
  - `react-router-dom@^7.0.0`
@@ -23,6 +29,57 @@ npm install @mui-toolpad-extended-tuni/users
23
29
  - `axios@^1.7.0`
24
30
  - `zustand@^4.5.0`
25
31
 
32
+ ### Installation Example
33
+
34
+ ```bash
35
+ npm install @mui-toolpad-extended-tuni/users @mui-toolpad-extended-tuni/main @mui-toolpad-extended-tuni/core \
36
+ react react-dom react-router-dom \
37
+ @mui/material @mui/icons-material \
38
+ @emotion/react @emotion/styled \
39
+ axios zustand
40
+ ```
41
+
42
+ ## API Configuration
43
+
44
+ This package uses configurable API endpoints. You can customize all endpoints via the `apiConfig` prop in `ToolpadProvider`.
45
+
46
+ ### Default Endpoints
47
+
48
+ If no configuration is provided, the package uses these default endpoints:
49
+
50
+ - `getCurrent: "api/users/current/"` - GET current authenticated user
51
+ - `get: "api/users/"` - GET list of users
52
+ - `post: "api/users/"` - POST create new user
53
+ - `put: "api/users/:id/"` - PUT update user (use `:id` placeholder)
54
+ - `delete: "api/users/:id/"` - DELETE user (use `:id` placeholder)
55
+ - `logout: "/auth/lti_logout/"` - POST logout user
56
+
57
+ ### Customizing Endpoints
58
+
59
+ Configure endpoints via `ToolpadProvider`:
60
+
61
+ ```tsx
62
+ import { ToolpadProvider } from '@mui-toolpad-extended-tuni/main';
63
+ import type { UsersApiEndpoints } from '@mui-toolpad-extended-tuni/users';
64
+
65
+ const apiConfig = {
66
+ users: {
67
+ getCurrent: "https://api.example.com/v1/users/me",
68
+ get: "https://api.example.com/v1/users",
69
+ post: "https://api.example.com/v1/users",
70
+ put: "https://api.example.com/v1/users/:id",
71
+ delete: "https://api.example.com/v1/users/:id",
72
+ logout: "https://api.example.com/v1/auth/logout",
73
+ } as UsersApiEndpoints,
74
+ };
75
+
76
+ <ToolpadProvider apiConfig={apiConfig}>
77
+ {/* Your app */}
78
+ </ToolpadProvider>
79
+ ```
80
+
81
+ **Note**: You can use either full URLs or relative paths. Placeholders like `:id` will be replaced with actual values at runtime.
82
+
26
83
  ## Usage
27
84
 
28
85
  ### Basic Setup
@@ -94,6 +151,261 @@ function App() {
94
151
  }
95
152
  ```
96
153
 
154
+ ## API Endpoints
155
+
156
+ This package makes the following API calls. All endpoints are configurable via `apiConfig`.
157
+
158
+ ### GET `/api/users/current/` (or configured `getCurrent` endpoint)
159
+
160
+ Retrieves the currently authenticated user.
161
+
162
+ **Request**: No body required (uses session/cookies for authentication)
163
+
164
+ **Response**: `200 OK`
165
+ ```json
166
+ {
167
+ "id": "user-123",
168
+ "name": "John Doe",
169
+ "email": "john.doe@example.com",
170
+ "gender": "male",
171
+ "image": {
172
+ "large": "https://example.com/images/user-large.jpg",
173
+ "medium": "https://example.com/images/user-medium.jpg",
174
+ "thumbnail": "https://example.com/images/user-thumbnail.jpg"
175
+ },
176
+ "department": "Computer Science",
177
+ "platform_roles": ["user", "creator"],
178
+ "privacy_settings": {
179
+ "allow_analytics": true,
180
+ "allow_personalization": true,
181
+ "allow_communications": true,
182
+ "allow_third_party_sharing": false
183
+ },
184
+ "gdpr_consent": {
185
+ "accepted": true,
186
+ "accepted_date": "2024-01-15T10:00:00Z",
187
+ "last_updated": "2024-01-15T10:00:00Z"
188
+ },
189
+ "data_retention": {
190
+ "delete_account_after_inactivity": 365,
191
+ "delete_data_after_account_deletion": 30
192
+ },
193
+ "preferences": {
194
+ "navigation_type": "direct",
195
+ "visible_course_lists": {
196
+ "is_student": true,
197
+ "is_student_old": true,
198
+ "is_teacher": false,
199
+ "is_teacher_old": false,
200
+ "available": true
201
+ },
202
+ "last_visited_courses": ["COMP.CS.100:compcs100-fall-2024"],
203
+ "visible_navigation": ["Courses", "Calendar"]
204
+ }
205
+ }
206
+ ```
207
+
208
+ **Response Type**: `UserData`
209
+
210
+ ### GET `/api/users/` (or configured `get` endpoint)
211
+
212
+ Retrieves a list of users. Optionally filtered by course.
213
+
214
+ **Request Parameters** (query string):
215
+ - `course_id` (optional) - Filter users by course ID
216
+
217
+ **Example**: `GET /api/users/?course_id=course-123`
218
+
219
+ **Response**: `200 OK`
220
+ ```json
221
+ [
222
+ {
223
+ "id": "user-123",
224
+ "name": "John Doe",
225
+ "email": "john.doe@example.com",
226
+ // ... same structure as getCurrent
227
+ },
228
+ {
229
+ "id": "user-456",
230
+ "name": "Jane Smith",
231
+ "email": "jane.smith@example.com",
232
+ // ...
233
+ }
234
+ ]
235
+ ```
236
+
237
+ **Response Type**: `UserData[]`
238
+
239
+ ### POST `/api/users/` (or configured `post` endpoint)
240
+
241
+ Creates a new user.
242
+
243
+ **Request Body**: `Partial<UserData>` (snake_case)
244
+ ```json
245
+ {
246
+ "name": "John Doe",
247
+ "email": "john.doe@example.com",
248
+ "gender": "male",
249
+ "department": "Computer Science",
250
+ "platform_roles": ["user"],
251
+ "privacy_settings": {
252
+ "allow_analytics": true,
253
+ "allow_personalization": true,
254
+ "allow_communications": true,
255
+ "allow_third_party_sharing": false
256
+ },
257
+ "gdpr_consent": {
258
+ "accepted": true,
259
+ "last_updated": "2024-01-15T10:00:00Z"
260
+ },
261
+ "data_retention": {
262
+ "delete_account_after_inactivity": 365,
263
+ "delete_data_after_account_deletion": 30
264
+ },
265
+ "preferences": {
266
+ "navigation_type": "direct",
267
+ "visible_course_lists": {
268
+ "is_student": true,
269
+ "is_student_old": true,
270
+ "is_teacher": false,
271
+ "is_teacher_old": false,
272
+ "available": true
273
+ },
274
+ "last_visited_courses": [],
275
+ "visible_navigation": ["Courses"]
276
+ }
277
+ }
278
+ ```
279
+
280
+ **Response**: `201 Created`
281
+ ```json
282
+ {
283
+ "id": "user-123",
284
+ "name": "John Doe",
285
+ // ... full UserData object with generated ID
286
+ }
287
+ ```
288
+
289
+ **Response Type**: `UserData`
290
+
291
+ **Note**: The request body should be in snake_case format. The package automatically converts from camelCase.
292
+
293
+ ### PUT `/api/users/:id/` (or configured `put` endpoint)
294
+
295
+ Updates an existing user.
296
+
297
+ **Request Parameters**:
298
+ - `:id` (path parameter) - User ID
299
+
300
+ **Request Body**: `UserData` (snake_case, must include `id`)
301
+ ```json
302
+ {
303
+ "id": "user-123",
304
+ "name": "Updated Name",
305
+ "email": "updated.email@example.com",
306
+ // ... all UserData fields
307
+ }
308
+ ```
309
+
310
+ **Response**: `200 OK`
311
+ ```json
312
+ {
313
+ "id": "user-123",
314
+ "name": "Updated Name",
315
+ // ... updated UserData object
316
+ }
317
+ ```
318
+
319
+ **Response Type**: `UserData`
320
+
321
+ ### DELETE `/api/users/:id/` (or configured `delete` endpoint)
322
+
323
+ Deletes a user.
324
+
325
+ **Request Parameters**:
326
+ - `:id` (path parameter) - User ID
327
+
328
+ **Response**: `200 OK` or `204 No Content`
329
+
330
+ **Response Type**: `void`
331
+
332
+ ### POST `/auth/lti_logout/` (or configured `logout` endpoint)
333
+
334
+ Logs out the current user (LTI logout).
335
+
336
+ **Request**: No body required
337
+
338
+ **Response**: `200 OK` or `204 No Content`
339
+
340
+ **Response Type**: `void`
341
+
342
+ ## Data Types
343
+
344
+ ### UserData
345
+
346
+ Complete user object returned by API.
347
+
348
+ ```typescript
349
+ interface UserData {
350
+ id: userId; // Unique user ID (string)
351
+ name: string; // User's full name
352
+ email: string; // User's email address
353
+ gender?: gender; // "male" | "female" | "other" (optional)
354
+ image?: { // User profile images (optional)
355
+ large: string; // Large image URL
356
+ medium: string; // Medium image URL
357
+ thumbnail: string; // Thumbnail image URL
358
+ };
359
+ department?: string; // User's department (optional)
360
+ platformRoles: PlatformRole[]; // Array of platform roles
361
+ privacySettings: { // Privacy preferences
362
+ allowAnalytics: boolean;
363
+ allowPersonalization: boolean;
364
+ allowCommunications: boolean;
365
+ allowThirdPartySharing: boolean;
366
+ };
367
+ gdprConsent: { // GDPR consent information
368
+ accepted: boolean;
369
+ acceptedDate?: string; // ISO date string (optional)
370
+ lastUpdated: string; // ISO date string
371
+ };
372
+ dataRetention: { // Data retention settings
373
+ deleteAccountAfterInactivity?: number; // Days (optional)
374
+ deleteDataAfterAccountDeletion?: number; // Days (optional)
375
+ };
376
+ preferences: { // User preferences
377
+ navigationType: navigationTypes; // "direct" | "instances"
378
+ visibleCourseLists: {
379
+ isStudent: boolean;
380
+ isStudentOld: boolean;
381
+ isTeacher: boolean;
382
+ isTeacherOld: boolean;
383
+ available: boolean;
384
+ };
385
+ lastVisitedCourses: string[]; // Array of "code:instance" strings
386
+ visibleNavigation: string[]; // Array of visible navigation items
387
+ };
388
+ }
389
+ ```
390
+
391
+ ### Type Definitions
392
+
393
+ ```typescript
394
+ type userId = string;
395
+ type navigationTypes = "direct" | "instances";
396
+ type gender = "male" | "female" | "other";
397
+ type PlatformRole = "admin" | "developer" | "moderator" | "creator" | "user" | "guest";
398
+ ```
399
+
400
+ ### Request/Response Format
401
+
402
+ **Important**: The backend API expects and returns data in **snake_case** format (e.g., `platform_roles`, `privacy_settings`). This package automatically converts between camelCase (used in TypeScript) and snake_case (used in API requests/responses).
403
+
404
+ **Example conversion**:
405
+ - TypeScript: `platformRoles` → API: `platform_roles`
406
+ - TypeScript: `privacySettings` → API: `privacy_settings`
407
+ - TypeScript: `lastVisitedCourses` → API: `last_visited_courses`
408
+
97
409
  ## Exports
98
410
 
99
411
  ### Components
@@ -105,15 +417,24 @@ function App() {
105
417
  ### Store
106
418
  - `useUserStore` - Zustand store for user management
107
419
 
420
+ ### Network Functions
421
+ - `getCurrentUser()` - Fetch current authenticated user
422
+ - `getUsers(courseId?: string)` - Fetch list of users (optionally filtered by course)
423
+ - `createUser(userData: Partial<UserData>)` - Create new user
424
+ - `updateUser(userData: UserData)` - Update existing user
425
+ - `deleteUser(userId: string)` - Delete user
426
+ - `logoutUser()` - Logout current user
427
+
108
428
  ### Configuration
109
429
  - `configureUserBus` - Configures UserBus with store methods (called automatically)
110
430
 
111
431
  ### Types
112
- - `UserData` - User data type (re-exported from main package)
113
- - `PlatformRole` - Platform role type (re-exported from main package)
114
- - `navigationTypes` - Navigation types (re-exported from main package)
115
- - `gender` - Gender type (re-exported from main package)
116
- - `userId` - User ID type (re-exported from main package)
432
+ - `UserData` - Complete user data type
433
+ - `UsersApiEndpoints` - API endpoint configuration type
434
+ - `PlatformRole` - Platform role type
435
+ - `navigationTypes` - Navigation types
436
+ - `gender` - Gender type
437
+ - `userId` - User ID type
117
438
 
118
439
  ## Features
119
440