@mui-toolpad-extended-tuni/core 3.2.0 → 3.3.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.
@@ -1,5 +1,5 @@
1
1
  import { default as React, ReactNode } from 'react';
2
- import { ApiConfig, CoursesApiEndpoints, UsersApiEndpoints, CalendarApiEndpoints } from './types';
2
+ import { StandardApiEndpoints } from './types';
3
3
  /**
4
4
  * Get the current API configuration from module-level store.
5
5
  * This can be called from non-React contexts (e.g., network functions).
@@ -9,15 +9,11 @@ import { ApiConfig, CoursesApiEndpoints, UsersApiEndpoints, CalendarApiEndpoints
9
9
  export declare const getApiConfig: () => ApiConfigContextValue | null;
10
10
  /**
11
11
  * API Configuration Context Value
12
- * Provides merged endpoint configurations for all microservices.
12
+ * Provides generic endpoint configuration registry for all microservices.
13
13
  */
14
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;
15
+ /** Map of service key to endpoint configuration */
16
+ endpoints: Map<string, StandardApiEndpoints>;
21
17
  /** Base URL for API requests (from axios config) */
22
18
  baseUrl: string;
23
19
  }
@@ -25,8 +21,6 @@ export interface ApiConfigContextValue {
25
21
  * Props for ApiConfigProvider component
26
22
  */
27
23
  export interface ApiConfigProviderProps {
28
- /** User-provided API configuration (optional) */
29
- apiConfig?: ApiConfig;
30
24
  /** Base URL for API requests (defaults to "/") */
31
25
  baseUrl?: string;
32
26
  /** Child components */
@@ -35,34 +29,58 @@ export interface ApiConfigProviderProps {
35
29
  /**
36
30
  * ApiConfigProvider Component
37
31
  *
38
- * Provides API endpoint configuration to all child components.
39
- * Merges user-provided configuration with default values for backward compatibility.
32
+ * Provides API endpoint configuration registry to all child components.
33
+ * Microservices register their endpoints via registerApiEndpoints().
40
34
  *
41
35
  * @example
42
36
  * ```tsx
43
- * <ApiConfigProvider
44
- * apiConfig={{
45
- * courses: {
46
- * get: "https://api.example.com/courses",
47
- * post: "https://api.example.com/courses"
48
- * }
49
- * }}
50
- * >
37
+ * <ApiConfigProvider baseUrl="/">
51
38
  * <YourApp />
52
39
  * </ApiConfigProvider>
53
40
  * ```
54
41
  */
55
42
  export declare const ApiConfigProvider: React.FC<ApiConfigProviderProps>;
56
43
  /**
57
- * Hook to access API configuration context.
44
+ * Register API endpoints for a microservice.
45
+ * This function can be called from any component or module-level code.
58
46
  *
59
- * @returns API configuration context value
47
+ * @param serviceKey - Unique identifier for the microservice (e.g., 'courses', 'users')
48
+ * @param endpoints - Endpoint configuration for the microservice (user-provided, will be merged with defaults)
49
+ *
50
+ * @example
51
+ * ```tsx
52
+ * registerApiEndpoints('courses', {
53
+ * get: "https://api.example.com/courses",
54
+ * post: "https://api.example.com/courses"
55
+ * });
56
+ * ```
57
+ */
58
+ export declare const registerApiEndpoints: (serviceKey: string, endpoints: StandardApiEndpoints) => void;
59
+ /**
60
+ * Hook to access API configuration for a specific service.
61
+ *
62
+ * @param serviceKey - The service key (e.g., 'courses', 'users', 'calendar')
63
+ * @returns Endpoint configuration for the specified service, or undefined if not registered
64
+ * @throws Error if used outside of ApiConfigProvider
65
+ *
66
+ * @example
67
+ * ```tsx
68
+ * const coursesConfig = useServiceApiConfig('courses');
69
+ * const endpoint = coursesConfig?.get; // "api/courses/" or user-provided value
70
+ * ```
71
+ */
72
+ export declare const useServiceApiConfig: (serviceKey: string) => StandardApiEndpoints | undefined;
73
+ /**
74
+ * Hook to access the full API configuration context.
75
+ * Generally prefer useServiceApiConfig() for accessing specific service configs.
76
+ *
77
+ * @returns Full API configuration context value
60
78
  * @throws Error if used outside of ApiConfigProvider
61
79
  *
62
80
  * @example
63
81
  * ```tsx
64
- * const { courses, users } = useApiConfig();
65
- * const endpoint = courses.get; // "api/courses/" or user-provided value
82
+ * const { endpoints, baseUrl } = useApiConfigContext();
83
+ * const coursesConfig = endpoints.get('courses');
66
84
  * ```
67
85
  */
68
- export declare const useApiConfig: () => ApiConfigContextValue;
86
+ export declare const useApiConfigContext: () => ApiConfigContextValue;
@@ -40,14 +40,7 @@ export interface UsersApiEndpoints extends StandardApiEndpoints {
40
40
  export interface CalendarApiEndpoints extends StandardApiEndpoints {
41
41
  }
42
42
  /**
43
- * Complete API configuration for all microservices.
44
- * Each microservice can be configured independently.
43
+ * Generic service API endpoints type alias.
44
+ * Allows microservices to define their own endpoint interfaces.
45
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
- }
46
+ export type ServiceApiEndpoints = StandardApiEndpoints;