api-core-lib 12.12.111 → 16.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/dist/index.d.ts CHANGED
@@ -1,11 +1,380 @@
1
- import { AxiosInstance, AxiosRequestConfig, Method, AxiosResponse, AxiosError } from 'axios';
2
- import { f as ApiClientConfig, A as ActionConfigModule, S as StandardResponse, g as ActionOptions, R as RequestConfig, h as ActionStateModule, Q as QueryOptions, i as UseApiQuery, j as ApiError, L as LogLevel } from './apiModule.types-hGWAkTwf.js';
3
- export { o as ActionConfig, u as ActionMethods, q as ActionState, s as ActionsWithQuery, a as ApiModuleConfig, E as ExecutableAction, r as ExecuteOptions, I as InputOf, m as Middleware, l as MiddlewareContext, d as ModuleActions, e as ModuleQueries, M as ModuleStates, O as OutputOf, P as PaginationMeta, n as RefreshTokenConfig, k as TokenManager, T as Tokens, U as UseApiConfig, b as UseApiModuleOptions, c as UseApiModuleReturn, p as UseApiState, V as ValidationError, t } from './apiModule.types-hGWAkTwf.js';
4
- export { c as UseApiRecordActions, U as UseApiRecordConfig, a as UseApiRecordReturn, b as UseApiRecordState } from './useApiRecord.types-BJop2XPB.js';
5
- import 'react';
1
+ import { InternalAxiosRequestConfig, AxiosResponse, AxiosRequestConfig, AxiosProgressEvent, AxiosInstance, Method } from 'axios';
2
+
3
+ /**
4
+ * @file src/types.ts
5
+ * @description This file serves as the central source for all data types and interfaces
6
+ * used throughout the library. Defining types here ensures consistency, type safety,
7
+ * and provides a clear API contract for the end-user.
8
+ */
9
+
10
+ /**
11
+ * Defines the structure for pagination metadata returned by the API.
12
+ */
13
+ interface PaginationMeta {
14
+ itemsPerPage: number;
15
+ totalItems: number;
16
+ currentPage: number;
17
+ totalPages: number;
18
+ }
19
+ /**
20
+ * Represents the standard wrapper that an API might use for its responses.
21
+ * @template T The type of the core data payload.
22
+ */
23
+ interface ApiResponse<T = any> {
24
+ success?: boolean;
25
+ data: T;
26
+ message?: string;
27
+ meta?: PaginationMeta;
28
+ }
29
+ /**
30
+ * Defines the structure for a single field validation error.
31
+ */
32
+ interface ValidationError {
33
+ field: string;
34
+ message: string;
35
+ }
36
+ /**
37
+ * Represents the unified error object produced by the library for any failed request.
38
+ */
39
+ interface ApiError {
40
+ message: string;
41
+ status: number;
42
+ code?: string;
43
+ errors?: ValidationError[];
44
+ requestId?: string;
45
+ }
46
+ /**
47
+ * The standardized, final response object that every library function returns.
48
+ * This is the primary type developers will interact with.
49
+ * @template T The type of the final, unwrapped data.
50
+ */
51
+ interface StandardResponse<T> {
52
+ data: T | null;
53
+ rawResponse: any;
54
+ error: ApiError | null;
55
+ loading: boolean;
56
+ success: boolean;
57
+ message?: string;
58
+ validationErrors?: ValidationError[];
59
+ }
60
+ /**
61
+ * Represents the set of authentication tokens managed by the library.
62
+ */
63
+ interface Tokens {
64
+ accessToken: string | null;
65
+ refreshToken: string | null;
66
+ expiresAt?: number;
67
+ tokenType?: string;
68
+ }
69
+ /**
70
+ * An interface for a token manager, allowing the logic for token storage to be decoupled.
71
+ * Consumers of the library can provide their own implementation (e.g., LocalStorage, Cookies).
72
+ */
73
+ interface TokenManager {
74
+ getTokens(): Promise<Tokens>;
75
+ setTokens(tokens: Tokens): Promise<void>;
76
+ clearTokens(): Promise<void>;
77
+ /**
78
+ * Determines the operating context.
79
+ * @returns `true` if tokens are in secure httpOnly cookies (server-side context).
80
+ * @returns `false` if tokens are accessible from the client (e.g., localStorage).
81
+ */
82
+ isHttpOnly(): boolean;
83
+ }
84
+ /**
85
+ * The context object passed to each middleware function in the pipeline.
86
+ */
87
+ interface MiddlewareContext {
88
+ req: InternalAxiosRequestConfig;
89
+ res?: AxiosResponse;
90
+ error?: any;
91
+ custom?: Record<string, any>;
92
+ }
93
+ /**
94
+ * Defines the signature for a middleware function.
95
+ */
96
+ type Middleware = (context: MiddlewareContext, next: () => Promise<void>) => Promise<void>;
97
+ /**
98
+ * Extends the default Axios request configuration with custom properties for the library.
99
+ */
100
+ interface RequestConfig extends AxiosRequestConfig {
101
+ /** If true, the request will bypass the token injection logic. */
102
+ isPublic?: boolean;
103
+ /** A key for managing request cancellation. */
104
+ cancelTokenKey?: string;
105
+ /** Callback for upload progress events. */
106
+ onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
107
+ /** Callback for download progress events. */
108
+ onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void;
109
+ }
110
+ /**
111
+ * Defines a flexible query options interface for pagination, sorting, filtering, and searching.
112
+ * Supports standard keys as well as any custom top-level query parameters.
113
+ * @example { page: 1, limit: 10, search: 'term', status: 'published' }
114
+ */
115
+ interface QueryOptions {
116
+ page?: number;
117
+ limit?: number;
118
+ search?: string;
119
+ sortBy?: {
120
+ key: string;
121
+ direction: 'asc' | 'desc';
122
+ }[];
123
+ filter?: Record<string, any>;
124
+ [key: string]: any;
125
+ }
126
+ /**
127
+ * Defines additional options for action methods like create, update, or delete.
128
+ */
129
+ interface ActionOptions extends RequestConfig {
130
+ /**
131
+ * Overrides the default endpoint for a specific action. Useful for specialized routes.
132
+ * @example update('123', { status: 'active' }, { endpoint: '/items/123/activate' })
133
+ */
134
+ endpoint?: string;
135
+ /**
136
+ * Overrides the `refetchAfterChange` setting for a single action.
137
+ */
138
+ refetch?: boolean;
139
+ }
140
+ /**
141
+ * The main configuration object for the `useApi` hook.
142
+ * @template T The data type the hook will manage.
143
+ */
144
+ interface UseApiConfig<T> {
145
+ /** The base API endpoint for the resource (e.g., '/users'). */
146
+ endpoint: string;
147
+ /** Initial data to populate the state before the first fetch. */
148
+ initialData?: T | null;
149
+ /** Default query options to use for the initial fetch. */
150
+ initialQuery?: QueryOptions;
151
+ /** If false, the hook will not fetch data automatically on mount. */
152
+ enabled?: boolean;
153
+ /** If true, data will be refetched automatically after a successful create, update, or delete action. */
154
+ refetchAfterChange?: boolean;
155
+ /** A default `RequestConfig` to apply to all GET requests made by the hook. */
156
+ requestConfig?: RequestConfig;
157
+ encodeQuery?: boolean;
158
+ pathParams?: Record<string, string | number>;
159
+ /** Callback function executed on a successful action. */
160
+ onSuccess?: (message: string, data?: T) => void;
161
+ /** Callback function executed on a failed action. */
162
+ onError?: (message: string, error?: ApiError) => void;
163
+ }
164
+ /**
165
+ * Defines the configuration for the automatic token refresh mechanism.
166
+ */
167
+ interface RefreshTokenConfig {
168
+ /** The API path for the token refresh endpoint (e.g., '/auth/refresh'). */
169
+ path: string;
170
+ /** A function to build the request body for the refresh call. */
171
+ buildRequestBody?: (refreshToken: string) => Record<string, any>;
172
+ /** A function to build any custom headers for the refresh call. */
173
+ buildRequestHeaders?: (currentTokens: Tokens) => Record<string, string>;
174
+ /**
175
+ * A function to extract the new tokens from the refresh API's response data.
176
+ * @param responseData The raw data from the refresh API response.
177
+ * @returns An object containing the new token details.
178
+ */
179
+ extractTokens: (responseData: any) => {
180
+ accessToken: string;
181
+ refreshToken?: string;
182
+ expiresIn: number;
183
+ tokenType?: string;
184
+ };
185
+ }
186
+ /**
187
+ * Defines the available levels for logging.
188
+ * 'debug': Logs everything.
189
+ * 'info': Logs standard requests and responses.
190
+ * 'warn': Logs warnings and errors.
191
+ * 'error': Logs only critical errors.
192
+ * 'silent': Disables all logging.
193
+ */
194
+ type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
195
+ /**
196
+ * An interface for a custom logger, compatible with the standard `console` object.
197
+ * It now includes a `debug` method for more granular logging.
198
+ */
199
+ /**
200
+ * The main configuration object for the `createApiClient` factory function.
201
+ */
202
+ interface ApiClientConfig {
203
+ /** The base URL for all API requests. */
204
+ baseURL?: string;
205
+ /** The token manager instance responsible for handling token storage. */
206
+ tokenManager: TokenManager;
207
+ /** The request timeout in milliseconds. */
208
+ timeout?: number;
209
+ /** Default headers to be sent with every request. */
210
+ headers?: Record<string, string>;
211
+ /** If true, cookies will be sent with cross-origin requests. */
212
+ withCredentials?: boolean;
213
+ /** Configuration for the automatic token refresh mechanism. */
214
+ refreshTokenConfig?: RefreshTokenConfig;
215
+ /** A callback function executed if the token refresh process fails. */
216
+ onRefreshError?: (error: any) => void;
217
+ /** A custom logger instance. Defaults to the browser `console`. */
218
+ /** An array of middleware functions to be executed with every request. */
219
+ middleware?: Middleware[];
220
+ /**
221
+ * Sets the verbosity of the internal logger.
222
+ * @default 'info'
223
+ */
224
+ logLevel?: LogLevel;
225
+ /**
226
+ * If true, all requests will be treated as public by default.
227
+ * A request can override this by explicitly setting `isPublic: false`.
228
+ * @default false
229
+ */
230
+ defaultIsPublic?: boolean;
231
+ maxTokenRefreshRetries?: number;
232
+ maxQueueSize?: number;
233
+ }
6
234
 
7
235
  declare function createApiClient(config: ApiClientConfig): AxiosInstance;
8
236
 
237
+ /**
238
+ * @file src/hooks/useApi.types.ts
239
+ * @description This file defines the professional, publicly-facing types for the `useApi` hook,
240
+ * providing a clean and stable contract for consumers.
241
+ */
242
+
243
+ /**
244
+ * Configuration object for the `useApi` hook.
245
+ * @template T The type of the data entity.
246
+ */
247
+ /**
248
+ * The primary state object managed by the `useApi` hook.
249
+ * It contains the fetched data, loading status, and any potential errors.
250
+ * @template T The type of the data entity being managed.
251
+ */
252
+ type UseApiState<T> = StandardResponse<T>;
253
+ /**
254
+ * A collection of callable functions for performing CRUD and other operations.
255
+ * These actions automatically handle state updates like loading and refetching.
256
+ * @template T The type of the data entity being managed.
257
+ */
258
+ interface UseApiActions<T, TListItem = T extends (infer U)[] ? U : T> {
259
+ fetch: () => Promise<void>;
260
+ create: (newItem: Partial<TListItem>, options?: ActionOptions) => Promise<StandardResponse<TListItem>>;
261
+ put: (id: string | number, item: TListItem, options?: ActionOptions) => Promise<StandardResponse<TListItem>>;
262
+ update: (id: string | number, updatedItem: Partial<TListItem>, options?: ActionOptions) => Promise<StandardResponse<TListItem>>;
263
+ remove: (id: string | number, options?: ActionOptions) => Promise<StandardResponse<any>>;
264
+ bulkRemove: (ids: Array<string | number>, options?: ActionOptions) => Promise<StandardResponse<any>>;
265
+ }
266
+ /**
267
+ * A collection of functions and properties for controlling the query parameters
268
+ * used for fetching data, such as pagination, sorting, and filtering.
269
+ */
270
+ interface UseApiQuery {
271
+ /** The current query options state. */
272
+ options: QueryOptions;
273
+ /** A function to set the entire query options object at once. */
274
+ setOptions: React.Dispatch<React.SetStateAction<QueryOptions>>;
275
+ /** Sets the current page number. */
276
+ setPage: (page: number) => void;
277
+ /** Sets the number of items per page and resets to the first page. */
278
+ setLimit: (limit: number) => void;
279
+ /** Sets the search term and resets to the first page. */
280
+ setSearchTerm: (search: string) => void;
281
+ /** Sets the sorting configuration. */
282
+ setSorting: (sortBy: {
283
+ key: string;
284
+ direction: 'asc' | 'desc';
285
+ }[]) => void;
286
+ /** Sets the filter object and resets to the first page. */
287
+ setFilters: (filter: Record<string, any>) => void;
288
+ /** Sets a single, custom query parameter. */
289
+ setQueryParam: (key: string, value: any) => void;
290
+ /** Resets the query options to their initial state. */
291
+ reset: () => void;
292
+ }
293
+ /**
294
+ * The complete return type of the `useApi` hook.
295
+ * It encapsulates the state, actions, and query controls for a given API resource.
296
+ * @template T The type of the data entity being managed.
297
+ */
298
+ interface UseApiReturn<T> {
299
+ state: UseApiState<T>;
300
+ setState: React.Dispatch<React.SetStateAction<UseApiState<T>>>;
301
+ actions: UseApiActions<T>;
302
+ query: UseApiQuery;
303
+ }
304
+
305
+ interface ActionConfig<TInput = any, TOutput = any> {
306
+ method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
307
+ path: string;
308
+ description?: string;
309
+ isList?: boolean;
310
+ invalidates?: string[];
311
+ autoFetch?: boolean;
312
+ upload?: boolean;
313
+ _input?: QueryOptions;
314
+ }
315
+ interface ApiModuleConfig {
316
+ baseEndpoint: string;
317
+ actions: Record<string, ActionConfig<any, any>>;
318
+ }
319
+ interface UrlSyncOptions<TModule extends ApiModuleConfig> {
320
+ searchParams: string;
321
+ updateUrl: (newSearchParams: string) => void;
322
+ actionsToSync: (keyof TModule['actions'])[];
323
+ defaultSyncAction?: keyof TModule['actions'];
324
+ }
325
+ interface UseApiModuleOptions<TModule extends ApiModuleConfig> {
326
+ onSuccess?: (actionName: string, message: string, data: any) => void;
327
+ onError?: (actionName: string, message: string, error?: ApiError | null) => void;
328
+ staleTime?: number;
329
+ cacheTime?: number;
330
+ refetchOnWindowFocus?: boolean;
331
+ dehydratedState?: Record<string, Partial<ActionState<any>>>;
332
+ urlSync?: UrlSyncOptions<TModule>;
333
+ initialActionsToExecute?: (keyof TModule['actions'])[];
334
+ defaultQueryOptions?: Partial<Record<keyof TModule['actions'], QueryOptions>>;
335
+ }
336
+ interface ActionState<TOutput> {
337
+ data: TOutput | null;
338
+ error: ApiError | null;
339
+ loading: boolean;
340
+ success: boolean;
341
+ called: boolean;
342
+ }
343
+ interface ExecutableAction<TInput, TOutput> {
344
+ state: ActionState<TOutput>;
345
+ execute: (input?: TInput, options?: {
346
+ pathParams?: Record<string, any>;
347
+ config?: AxiosRequestConfig;
348
+ query?: QueryOptions;
349
+ onSuccess?: (message: string, data?: TOutput) => void;
350
+ onError?: (message: string, error?: ApiError | null) => void;
351
+ }) => Promise<StandardResponse<TOutput>>;
352
+ reset: () => void;
353
+ query?: UseApiQuery;
354
+ }
355
+ type ModuleActions<TModule extends ApiModuleConfig> = {
356
+ [K in keyof TModule['actions']]: TModule['actions'][K] extends ActionConfig<infer TInput, infer TOutput> ? ExecutableAction<TInput, TOutput> : never;
357
+ };
358
+ type ModuleStates<TModule extends ApiModuleConfig> = {
359
+ [K in keyof TModule['actions']]: TModule['actions'][K] extends ActionConfig<any, infer TOutput> ? ActionState<TOutput> : never;
360
+ };
361
+ type ModuleQueries<TModule extends ApiModuleConfig> = {
362
+ [K in keyof TModule['actions']]: TModule['actions'][K]['isList'] extends true ? UseApiQuery : undefined;
363
+ };
364
+ interface UseApiModuleReturn<TModule extends ApiModuleConfig> {
365
+ actions: {
366
+ [K in keyof TModule['actions']]: ModuleActions<TModule>[K]['execute'];
367
+ };
368
+ states: ModuleStates<TModule>;
369
+ queries: ModuleQueries<TModule>;
370
+ refetch: (actionName: keyof TModule['actions']) => Promise<StandardResponse<any> | undefined>;
371
+ }
372
+
373
+ /**
374
+ * A factory function to create a reusable set of API services for a specific endpoint.
375
+ * It provides full CRUD operations plus advanced features like bulk deletion and file uploads,
376
+ * with intelligent, dynamic URL building.
377
+ */
9
378
  declare function createApiServices<T>(axiosInstance: AxiosInstance, baseEndpoint: string): {
10
379
  get: (id?: string | number, config?: ActionOptions) => Promise<StandardResponse<T>>;
11
380
  getWithQuery: (query: string, config?: RequestConfig) => Promise<StandardResponse<T>>;
@@ -16,11 +385,22 @@ declare function createApiServices<T>(axiosInstance: AxiosInstance, baseEndpoint
16
385
  bulkDelete: (ids: Array<string | number>, config?: ActionOptions) => Promise<StandardResponse<any>>;
17
386
  upload: (file: File, additionalData?: Record<string, any>, config?: ActionOptions) => Promise<StandardResponse<any>>;
18
387
  };
19
- declare function callDynamicApi(axiosInstance: AxiosInstance, baseEndpoint: string, actionConfig: ActionConfigModule<any, any>, params: {
20
- pathParams?: Record<string, string | number>;
21
- body?: any;
22
- config?: AxiosRequestConfig;
23
- }): Promise<StandardResponse<any>>;
388
+
389
+ /**
390
+ * @file src/core/utils.ts
391
+ * @description
392
+ * يحتوي هذا الملف على مجموعة من الدوال المساعدة المستخدمة في جميع أنحاء المكتبة،
393
+ * مثل بناء سلاسل الاستعلام (query strings) وإدارة إلغاء الطلبات،
394
+ * بالإضافة إلى دوال التحقق من الأنواع (type guards).
395
+ */
396
+
397
+ /**
398
+ * يبني سلسلة استعلام (query string) من كائن خيارات مرن.
399
+ * يتعامل مع البارامترات القياسية والمخصصة.
400
+ * @param query - كائن من نوع QueryOptions.
401
+ * @returns سلسلة استعلام جاهزة للإضافة للرابط.
402
+ */
403
+ declare function buildPaginateQuery(query: QueryOptions): string;
24
404
 
25
405
  /**
26
406
  * Defines a single custom API action.
@@ -56,57 +436,6 @@ declare function createApiActions<TActions extends Record<string, {
56
436
  [K in keyof TActions]: ApiAction<TActions[K]['requestType'], TActions[K]['responseType']>;
57
437
  };
58
438
 
59
- declare class GlobalStateManager {
60
- private store;
61
- getSnapshot<T>(key: string): ActionStateModule<T>;
62
- /**
63
- * يسجل دالة callback للاستماع إلى التغييرات على مفتاح معين.
64
- * @returns دالة لإلغاء الاشتراك.
65
- */
66
- subscribe(key: string, callback: () => void): () => void;
67
- /**
68
- * يحدّث الحالة لمفتاح معين ويقوم بإعلام جميع المشتركين.
69
- */
70
- setState<T>(key: string, updater: (prevState: ActionStateModule<T>) => ActionStateModule<T>): void;
71
- /**
72
- * يجعل البيانات المرتبطة بمفتاح معين "قديمة" (stale).
73
- */
74
- invalidate(key: string): void;
75
- /**
76
- * [نسخة محدثة وأكثر قوة]
77
- * يجعل كل البيانات التي تبدأ بمفتاح معين "قديمة" (stale).
78
- * @example invalidateByPrefix('myModule/list::') سيبطل كل صفحات القائمة.
79
- */
80
- invalidateByPrefix(prefix: string): void;
81
- /**
82
- * Serializes the current state of the query store into a JSON string.
83
- * This is used on the server to pass the initial state to the client.
84
- * @returns A JSON string representing the dehydrated state.
85
- */
86
- dehydrate(): string;
87
- /**
88
- * Merges a dehydrated state object into the current store.
89
- * This is used on the client to hydrate the state received from the server.
90
- * @param hydratedState - A JSON string from the `dehydrate` method.
91
- */
92
- rehydrate(hydratedState: string): void;
93
- }
94
- declare const globalStateManager: GlobalStateManager;
95
-
96
- /**
97
- * [نسخة مطورة] يبني سلسلة استعلام (query string) من كائن الخيارات.
98
- * يدعم الآن الفلاتر المتداخلة (filter[key]=value) والترتيب المتعدد.
99
- * @param options - كائن خيارات الاستعلام (فلترة, ترتيب, ...).
100
- * @returns سلسلة استعلام جاهزة للإضافة للرابط.
101
- */
102
- declare function buildPaginateQuery(options: QueryOptions): string;
103
-
104
- /**
105
- * [النسخة النهائية والمضمونة]
106
- * تستخدم دوال حماية النوع المخصصة للقضاء على أخطاء 'never' بشكل نهائي.
107
- */
108
- declare const processResponse: <T>(responseOrError: AxiosResponse<any> | AxiosError) => StandardResponse<T>;
109
-
110
439
  interface CacheItem<T> {
111
440
  data: T;
112
441
  timestamp: number;
@@ -118,63 +447,25 @@ declare class CacheManager {
118
447
  set<T>(key: string, data: T, duration?: number): void;
119
448
  get<T>(key: string): T | null;
120
449
  /**
121
- * [FIX] تم تحويلها إلى دالة عامة (generic) لتعيد النوع الصحيح.
122
- * الآن بدلًا من إرجاع CacheItem<unknown>، ستُرجع CacheItem<T>.
450
+ * [دالة جديدة] تعيد عنصر الـ Cache بالكامل (البيانات + معلومات إضافية)
451
+ * دون حذفه عند انتهاء الصلاحية. هذا يسمح لنا بتطبيق منطق stale-while-revalidate.
123
452
  */
124
453
  getWithMeta<T>(key: string): CacheItem<T> | null;
125
454
  delete(key: string): void;
126
455
  clear(): void;
456
+ /**
457
+ * [دالة جديدة] تقوم بإبطال (حذف) جميع عناصر الـ Cache التي تبدأ ببادئة معينة.
458
+ * أساسية لعملية invalidation التلقائية.
459
+ */
127
460
  invalidateByPrefix(prefix: string): void;
128
461
  }
129
462
  declare const cacheManager: CacheManager;
130
463
 
131
- /**
132
- * يقوم بإنشاء مفتاح تخزين مؤقت فريد وثابت لإجراء معين ومدخلاته.
133
- * هذا يضمن أن نفس الطلب ينتج دائمًا نفس المفتاح.
134
- * @param moduleName - عادةً ما يكون `baseEndpoint` للموديول.
135
- * @param actionName - اسم الإجراء (مثل 'list', 'create').
136
- * @param input - بيانات الطلب (body/query params).
137
- * @param callOptions - خيارات إضافية مثل `pathParams`.
138
- * @returns سلسلة نصية فريدة تمثل مفتاح التخزين المؤقت.
139
- */
140
- declare const generateCacheKey: (moduleName: string, actionName: string, input?: unknown, callOptions?: {
141
- pathParams?: Record<string, any>;
142
- }) => string;
464
+ declare const processResponse: <T>(responseOrError: AxiosResponse<any> | ApiError) => StandardResponse<T>;
143
465
 
144
- /**
145
- * @file src/hooks/useApi.types.ts
146
- * @description This file defines the professional, publicly-facing types for the `useApi` hook,
147
- * providing a clean and stable contract for consumers.
148
- */
466
+ declare function useApi<T>(axiosInstance: AxiosInstance, config: UseApiConfig<T>): UseApiReturn<T>;
149
467
 
150
- /**
151
- * Configuration object for the `useApi` hook.
152
- * @template T The type of the data entity.
153
- */
154
- /**
155
- * A collection of callable functions for performing CRUD and other operations.
156
- * These actions automatically handle state updates like loading and refetching.
157
- * @template T The type of the data entity being managed.
158
- */
159
- interface UseApiActions<T, TListItem = T extends (infer U)[] ? U : T> {
160
- fetch: (querryOptions?: QueryOptions) => Promise<void>;
161
- create: (newItem: Partial<TListItem>, options?: ActionOptions) => Promise<StandardResponse<TListItem>>;
162
- put: (id: string | number, item: TListItem, options?: ActionOptions) => Promise<StandardResponse<TListItem>>;
163
- update: (id: string | number, updatedItem: Partial<TListItem>, options?: ActionOptions) => Promise<StandardResponse<TListItem>>;
164
- remove: (id: string | number, options?: ActionOptions) => Promise<StandardResponse<any>>;
165
- bulkRemove: (ids: Array<string | number>, options?: ActionOptions) => Promise<StandardResponse<any>>;
166
- }
167
- /**
168
- * The complete return type of the `useApi` hook.
169
- * It encapsulates the state, actions, and query controls for a given API resource.
170
- * @template T The type of the data entity being managed.
171
- */
172
- interface UseApiReturn<T> {
173
- state: StandardResponse<T>;
174
- setState: React.Dispatch<React.SetStateAction<StandardResponse<T>>>;
175
- actions: UseApiActions<T>;
176
- query: UseApiQuery;
177
- }
468
+ declare function useApiModule<TModule extends ApiModuleConfig>(axiosInstance: AxiosInstance, moduleConfig: TModule, options?: UseApiModuleOptions<TModule>): UseApiModuleReturn<TModule>;
178
469
 
179
470
  type ApiResourceStatus = 'idle' | 'loading' | 'success' | 'error';
180
471
  interface UseApiResourceState<T> {
@@ -222,4 +513,4 @@ interface UseApiResourceReturn<T, TCreate, TUpdate, TPathParams> {
222
513
  setQuery: React.Dispatch<React.SetStateAction<QueryOptions>>;
223
514
  }
224
515
 
225
- export { ActionConfigModule, ActionOptions, ActionStateModule, ApiClientConfig, ApiError, type ApiResourceStatus, LogLevel, QueryOptions, RequestConfig, StandardResponse, type UseApiActions, UseApiQuery, type UseApiResourceActions, type UseApiResourceConfig, type UseApiResourceReturn, type UseApiResourceState, type UseApiReturn, buildPaginateQuery, cacheManager, callDynamicApi, createApiActions, createApiClient, createApiServices, generateCacheKey, globalStateManager, processResponse };
516
+ export { type ActionConfig, type ActionOptions, type ActionState, type ApiClientConfig, type ApiError, type ApiModuleConfig, type ApiResourceStatus, type ApiResponse, type ExecutableAction, type LogLevel, type Middleware, type MiddlewareContext, type ModuleActions, type ModuleQueries, type ModuleStates, type PaginationMeta, type QueryOptions, type RefreshTokenConfig, type RequestConfig, type StandardResponse, type TokenManager, type Tokens, type UrlSyncOptions, type UseApiActions, type UseApiConfig, type UseApiModuleOptions, type UseApiModuleReturn, type UseApiQuery, type UseApiResourceActions, type UseApiResourceConfig, type UseApiResourceReturn, type UseApiResourceState, type UseApiReturn, type UseApiState, type ValidationError, buildPaginateQuery, cacheManager, createApiActions, createApiClient, createApiServices, processResponse, useApi, useApiModule };