@mui-toolpad-extended-tuni/core 3.1.0 → 3.2.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 +15 -2
- package/dist/API/ApiConfigContext.d.ts +68 -0
- package/dist/API/types.d.ts +53 -0
- package/dist/API/utils.d.ts +34 -0
- package/dist/index.cjs +53 -53
- package/dist/index.d.ts +5 -1
- package/dist/index.es.js +3331 -3246
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,10 +10,13 @@ This package contains shared dependencies used by all microservices in the MUI T
|
|
|
10
10
|
npm install @mui-toolpad-extended-tuni/core
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
**Note**: This package is typically installed as a peer dependency of `@mui-toolpad-extended-tuni/main` or other extension packages. You usually don't need to install it directly unless you're using it standalone.
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
## Required Peer Dependencies
|
|
16
16
|
|
|
17
|
+
This package requires the following peer dependencies to be installed:
|
|
18
|
+
|
|
19
|
+
### React & UI Framework
|
|
17
20
|
- `@emotion/react`: ^11.0.0
|
|
18
21
|
- `@emotion/styled`: ^11.0.0
|
|
19
22
|
- `@mui/icons-material`: ^7.0.0
|
|
@@ -25,6 +28,16 @@ This package requires the following peer dependencies:
|
|
|
25
28
|
- `react-router-dom`: ^7.0.0
|
|
26
29
|
- `zustand`: ^4.5.0
|
|
27
30
|
|
|
31
|
+
### Installation Example
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install @mui-toolpad-extended-tuni/core \
|
|
35
|
+
@emotion/react @emotion/styled \
|
|
36
|
+
@mui/icons-material @mui/material @mui/x-date-pickers \
|
|
37
|
+
@toolpad/core \
|
|
38
|
+
react react-dom react-router-dom zustand
|
|
39
|
+
```
|
|
40
|
+
|
|
28
41
|
## Features
|
|
29
42
|
|
|
30
43
|
### Events
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { default as React, ReactNode } from 'react';
|
|
2
|
+
import { ApiConfig, CoursesApiEndpoints, UsersApiEndpoints, CalendarApiEndpoints } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Get the current API configuration from module-level store.
|
|
5
|
+
* This can be called from non-React contexts (e.g., network functions).
|
|
6
|
+
*
|
|
7
|
+
* @returns Current API configuration or null if not initialized
|
|
8
|
+
*/
|
|
9
|
+
export declare const getApiConfig: () => ApiConfigContextValue | null;
|
|
10
|
+
/**
|
|
11
|
+
* API Configuration Context Value
|
|
12
|
+
* Provides merged endpoint configurations for all microservices.
|
|
13
|
+
*/
|
|
14
|
+
export interface ApiConfigContextValue {
|
|
15
|
+
/** Courses microservice endpoints (merged with defaults) */
|
|
16
|
+
courses: CoursesApiEndpoints;
|
|
17
|
+
/** Users microservice endpoints (merged with defaults) */
|
|
18
|
+
users: UsersApiEndpoints;
|
|
19
|
+
/** Calendar microservice endpoints (merged with defaults) */
|
|
20
|
+
calendar: CalendarApiEndpoints;
|
|
21
|
+
/** Base URL for API requests (from axios config) */
|
|
22
|
+
baseUrl: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Props for ApiConfigProvider component
|
|
26
|
+
*/
|
|
27
|
+
export interface ApiConfigProviderProps {
|
|
28
|
+
/** User-provided API configuration (optional) */
|
|
29
|
+
apiConfig?: ApiConfig;
|
|
30
|
+
/** Base URL for API requests (defaults to "/") */
|
|
31
|
+
baseUrl?: string;
|
|
32
|
+
/** Child components */
|
|
33
|
+
children: ReactNode;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* ApiConfigProvider Component
|
|
37
|
+
*
|
|
38
|
+
* Provides API endpoint configuration to all child components.
|
|
39
|
+
* Merges user-provided configuration with default values for backward compatibility.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* <ApiConfigProvider
|
|
44
|
+
* apiConfig={{
|
|
45
|
+
* courses: {
|
|
46
|
+
* get: "https://api.example.com/courses",
|
|
47
|
+
* post: "https://api.example.com/courses"
|
|
48
|
+
* }
|
|
49
|
+
* }}
|
|
50
|
+
* >
|
|
51
|
+
* <YourApp />
|
|
52
|
+
* </ApiConfigProvider>
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare const ApiConfigProvider: React.FC<ApiConfigProviderProps>;
|
|
56
|
+
/**
|
|
57
|
+
* Hook to access API configuration context.
|
|
58
|
+
*
|
|
59
|
+
* @returns API configuration context value
|
|
60
|
+
* @throws Error if used outside of ApiConfigProvider
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```tsx
|
|
64
|
+
* const { courses, users } = useApiConfig();
|
|
65
|
+
* const endpoint = courses.get; // "api/courses/" or user-provided value
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare const useApiConfig: () => ApiConfigContextValue;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** @format */
|
|
2
|
+
/**
|
|
3
|
+
* Standard CRUD API endpoints interface.
|
|
4
|
+
* All microservice endpoint configurations extend this base interface.
|
|
5
|
+
*/
|
|
6
|
+
export interface StandardApiEndpoints {
|
|
7
|
+
/** GET endpoint for retrieving a list of resources */
|
|
8
|
+
get?: string;
|
|
9
|
+
/** GET endpoint for retrieving a single resource by ID. Use :id placeholder for the ID */
|
|
10
|
+
getById?: string;
|
|
11
|
+
/** POST endpoint for creating a new resource */
|
|
12
|
+
post?: string;
|
|
13
|
+
/** PUT endpoint for updating an existing resource. Use :id placeholder for the ID */
|
|
14
|
+
put?: string;
|
|
15
|
+
/** DELETE endpoint for deleting a resource. Use :id placeholder for the ID */
|
|
16
|
+
delete?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Courses microservice API endpoints configuration.
|
|
20
|
+
* Extends StandardApiEndpoints with course-specific endpoints.
|
|
21
|
+
*/
|
|
22
|
+
export interface CoursesApiEndpoints extends StandardApiEndpoints {
|
|
23
|
+
/** GET endpoint for retrieving a course by URL. Use :encodedUrl placeholder for base64-encoded URL */
|
|
24
|
+
getByUrl?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Users microservice API endpoints configuration.
|
|
28
|
+
* Extends StandardApiEndpoints with user-specific endpoints.
|
|
29
|
+
*/
|
|
30
|
+
export interface UsersApiEndpoints extends StandardApiEndpoints {
|
|
31
|
+
/** GET endpoint for retrieving the current authenticated user */
|
|
32
|
+
getCurrent?: string;
|
|
33
|
+
/** POST endpoint for user logout */
|
|
34
|
+
logout?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Calendar microservice API endpoints configuration.
|
|
38
|
+
* Extends StandardApiEndpoints with calendar-specific endpoints.
|
|
39
|
+
*/
|
|
40
|
+
export interface CalendarApiEndpoints extends StandardApiEndpoints {
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Complete API configuration for all microservices.
|
|
44
|
+
* Each microservice can be configured independently.
|
|
45
|
+
*/
|
|
46
|
+
export interface ApiConfig {
|
|
47
|
+
/** Courses microservice endpoint configuration */
|
|
48
|
+
courses?: CoursesApiEndpoints;
|
|
49
|
+
/** Users microservice endpoint configuration */
|
|
50
|
+
users?: UsersApiEndpoints;
|
|
51
|
+
/** Calendar microservice endpoint configuration */
|
|
52
|
+
calendar?: CalendarApiEndpoints;
|
|
53
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { StandardApiEndpoints, CoursesApiEndpoints, UsersApiEndpoints, CalendarApiEndpoints } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Builds a complete URL from a base URL and endpoint path.
|
|
4
|
+
* Handles both absolute URLs and relative paths.
|
|
5
|
+
* Supports query parameters in endpoint strings.
|
|
6
|
+
*
|
|
7
|
+
* @param baseUrl - Base URL (e.g., "https://api.example.com" or "/")
|
|
8
|
+
* @param endpoint - Endpoint path (e.g., "api/courses/" or "api/courses/?encoded_url=:encodedUrl")
|
|
9
|
+
* @param params - Optional parameters to replace placeholders (e.g., { id: "123", encodedUrl: "base64string" })
|
|
10
|
+
* @returns Complete URL string
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* buildUrl("/", "api/courses/:id", { id: "123" }) // "/api/courses/123"
|
|
14
|
+
* buildUrl("/", "api/courses/?encoded_url=:encodedUrl", { encodedUrl: "abc123" }) // "/api/courses/?encoded_url=abc123"
|
|
15
|
+
* buildUrl("https://api.example.com", "courses/:id", { id: "123" }) // "https://api.example.com/courses/123"
|
|
16
|
+
*/
|
|
17
|
+
export declare function buildUrl(baseUrl: string, endpoint: string, params?: Record<string, string | number>): string;
|
|
18
|
+
/**
|
|
19
|
+
* Gets default endpoint values for a microservice.
|
|
20
|
+
* These match the current hardcoded values for backward compatibility.
|
|
21
|
+
*
|
|
22
|
+
* @param service - The microservice name
|
|
23
|
+
* @returns Default endpoint configuration
|
|
24
|
+
*/
|
|
25
|
+
export declare function getDefaultEndpoints(service: 'courses' | 'users' | 'calendar'): StandardApiEndpoints | CoursesApiEndpoints | UsersApiEndpoints | CalendarApiEndpoints;
|
|
26
|
+
/**
|
|
27
|
+
* Merges user-provided endpoints with defaults.
|
|
28
|
+
* User endpoints take precedence over defaults.
|
|
29
|
+
*
|
|
30
|
+
* @param defaults - Default endpoint configuration
|
|
31
|
+
* @param userEndpoints - User-provided endpoint configuration (optional)
|
|
32
|
+
* @returns Merged endpoint configuration
|
|
33
|
+
*/
|
|
34
|
+
export declare function mergeEndpoints<T extends StandardApiEndpoints>(defaults: T, userEndpoints?: Partial<T>): T;
|