@mui-toolpad-extended-tuni/main 3.4.0 → 3.5.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
@@ -2,6 +2,12 @@
2
2
 
3
3
  Main package for MUI Toolpad Extended TUNI - provides ToolpadProvider, LMS components, and platform features.
4
4
 
5
+ ## Version 3.4.1
6
+
7
+ **Bug Fixes:**
8
+ - Fixed build issue where `useApiConfig` was incorrectly referenced (removed in v3.3.0). The package now correctly uses `useServiceApiConfig` and `useApiConfigContext` from core.
9
+ - **Breaking Change**: Removed re-exports of `react-router-dom` components (`BrowserRouter`, `Routes`, `Route`, `Navigate`, `Outlet`, `Link`, hooks, etc.). Since `react-router-dom` is a peer dependency, import these directly from `react-router-dom` to avoid type mismatches and ensure compatibility with your React version.
10
+
5
11
  ## Installation
6
12
 
7
13
  ```bash
@@ -60,12 +66,16 @@ npm install @mui-toolpad-extended-tuni/users
60
66
 
61
67
  ```tsx
62
68
  import { BrowserRouter } from 'react-router-dom';
63
- import { ToolpadProvider } from '@mui-toolpad-extended-tuni/main';
69
+ import { ToolpadProvider, Microservices } from '@mui-toolpad-extended-tuni/main';
64
70
 
65
71
  function App() {
66
72
  return (
67
73
  <BrowserRouter>
68
- <ToolpadProvider>{/* Your application content */}</ToolpadProvider>
74
+ <ToolpadProvider>
75
+ <Microservices>
76
+ {/* Your application content */}
77
+ </Microservices>
78
+ </ToolpadProvider>
69
79
  </BrowserRouter>
70
80
  );
71
81
  }
@@ -82,8 +92,117 @@ import {
82
92
  Notifications,
83
93
  Dialogs,
84
94
  } from '@mui-toolpad-extended-tuni/main';
95
+
96
+ // Import router components and hooks directly from react-router-dom
97
+ // (react-router-dom is a peer dependency, so import directly to avoid type mismatches)
98
+ import { Routes, Route, Navigate, Outlet, useNavigate, useParams, Link } from 'react-router-dom';
99
+ ```
100
+
101
+ ## API Configuration
102
+
103
+ Each microservice accepts its own `apiEndpoints` prop, allowing you to configure endpoints independently. This modular approach means you only configure endpoints for the microservices you actually use.
104
+
105
+ ### Basic Configuration
106
+
107
+ Configure endpoints directly on each microservice component:
108
+
109
+ ```tsx
110
+ import { CourseMicroservice } from '@mui-toolpad-extended-tuni/courses';
111
+ import { UserMicroservice } from '@mui-toolpad-extended-tuni/users';
112
+ import type { CoursesApiEndpoints, UsersApiEndpoints } from '@mui-toolpad-extended-tuni/core';
113
+
114
+ const coursesEndpoints: CoursesApiEndpoints = {
115
+ get: "https://api.example.com/v1/courses",
116
+ getById: "https://api.example.com/v1/courses/:id",
117
+ post: "https://api.example.com/v1/courses",
118
+ put: "https://api.example.com/v1/courses/:id",
119
+ delete: "https://api.example.com/v1/courses/:id",
120
+ };
121
+
122
+ const usersEndpoints: UsersApiEndpoints = {
123
+ getCurrent: "https://api.example.com/v1/users/me",
124
+ get: "https://api.example.com/v1/users",
125
+ post: "https://api.example.com/v1/users",
126
+ put: "https://api.example.com/v1/users/:id",
127
+ delete: "https://api.example.com/v1/users/:id",
128
+ logout: "https://api.example.com/v1/auth/logout",
129
+ };
130
+
131
+ <ToolpadProvider>
132
+ <Microservices>
133
+ <CourseMicroservice apiEndpoints={coursesEndpoints}>
134
+ {/* Your course microservices */}
135
+ </CourseMicroservice>
136
+ <UserMicroservice apiEndpoints={usersEndpoints} />
137
+ </Microservices>
138
+ </ToolpadProvider>
85
139
  ```
86
140
 
141
+ ### URL Format Guidelines
142
+
143
+ You can use either:
144
+
145
+ 1. **Full URLs**: `"https://api.example.com/v1/courses"`
146
+ - Use when your API is on a different domain
147
+ - Supports both HTTP and HTTPS
148
+
149
+ 2. **Relative Paths**: `"api/courses/"` or `"/api/courses/"`
150
+ - Use when your API is on the same domain
151
+ - Relative paths are resolved against the base URL (defaults to `/`)
152
+
153
+ ### Placeholder Support
154
+
155
+ Endpoints can include placeholders that are replaced at runtime:
156
+
157
+ - `:id` - Replaced with the actual resource ID
158
+ - `:courseId` - Replaced with course ID
159
+ - `:encodedUrl` - Replaced with base64-encoded URL (for courses)
160
+
161
+ **Example**:
162
+ ```tsx
163
+ <CourseMicroservice apiEndpoints={{
164
+ getById: "api/courses/:id", // :id will be replaced with actual course ID
165
+ put: "api/courses/:id/", // Same placeholder support
166
+ }}>
167
+ {/* Your course microservices */}
168
+ </CourseMicroservice>
169
+ ```
170
+
171
+ ### Default Endpoints
172
+
173
+ If no `apiEndpoints` prop is provided, each microservice uses its default endpoints. See each microservice's README for their default endpoint values.
174
+
175
+ ### Partial Configuration
176
+
177
+ You can configure only the endpoints you need to customize. Unspecified endpoints will use defaults:
178
+
179
+ ```tsx
180
+ <CourseMicroservice apiEndpoints={{
181
+ get: "https://custom-api.com/courses", // Only override GET
182
+ // Other endpoints use defaults
183
+ }}>
184
+ {/* Your course microservices */}
185
+ </CourseMicroservice>
186
+ ```
187
+
188
+ ### Accessing Configuration
189
+
190
+ Each microservice provides its own hook for accessing configuration. No need to know service keys:
191
+
192
+ ```tsx
193
+ import { useCoursesApiConfig } from '@mui-toolpad-extended-tuni/courses';
194
+ import { useUsersApiConfig } from '@mui-toolpad-extended-tuni/users';
195
+
196
+ function MyComponent() {
197
+ const coursesConfig = useCoursesApiConfig();
198
+ const usersConfig = useUsersApiConfig();
199
+ const coursesEndpoint = coursesConfig?.get; // "api/courses/" or custom value
200
+ const usersEndpoint = usersConfig?.getCurrent; // "api/users/current/" or custom value
201
+ }
202
+ ```
203
+
204
+ Each microservice package exports its own hook - developers never need to know internal service keys!
205
+
87
206
  ## Features
88
207
 
89
208
  ### ToolpadProvider
@@ -121,7 +240,7 @@ If you're migrating from the deprecated `mui-toolpad-extended-tuni` package:
121
240
  ```json
122
241
  {
123
242
  "dependencies": {
124
- "@mui-toolpad-extended-tuni/main": "^3.4.0"
243
+ "@mui-toolpad-extended-tuni/main": "^3.5.0"
125
244
  }
126
245
  }
127
246
  ```
@@ -129,12 +248,15 @@ If you're migrating from the deprecated `mui-toolpad-extended-tuni` package:
129
248
  2. Update all imports:
130
249
  ```typescript
131
250
  // Old (deprecated)
132
- import { ToolpadProvider } from 'mui-toolpad-extended-tuni';
251
+ import { ToolpadProvider, BrowserRouter } from 'mui-toolpad-extended-tuni';
133
252
 
134
253
  // New
135
254
  import { ToolpadProvider } from '@mui-toolpad-extended-tuni/main';
255
+ import { BrowserRouter } from 'react-router-dom';
136
256
  ```
137
257
 
258
+ **Note**: Router components (`BrowserRouter`, `Routes`, `Route`, `Navigate`, `Outlet`, etc.) and hooks (`useNavigate`, `useParams`, `useLocation`, etc.) should be imported directly from `react-router-dom`, not from `@mui-toolpad-extended-tuni/main`.
259
+
138
260
  ## License
139
261
 
140
262
  MIT
@@ -1,5 +1,4 @@
1
1
  import { ReactNode } from 'react';
2
- import { ApiConfig } from '../../core/src';
3
2
  export interface LogoConfig {
4
3
  sidebarFooter?: {
5
4
  smallLogo?: string;
@@ -10,8 +9,6 @@ export interface LogoConfig {
10
9
  export interface ToolpadProviderProps {
11
10
  children?: ReactNode;
12
11
  logos?: LogoConfig;
13
- /** API endpoint configuration for microservices. Each microservice can define its own endpoints. */
14
- apiConfig?: ApiConfig;
15
12
  }
16
13
  export declare const useLogoContext: () => LogoConfig;
17
14
  /**