api-core-lib 11.7.6 → 11.8.7
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.mts +9 -41
- package/dist/index.d.ts +9 -41
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { InternalAxiosRequestConfig, AxiosResponse, AxiosRequestConfig, AxiosProgressEvent, AxiosInstance, Method } from 'axios';
|
|
2
2
|
|
|
3
|
+
interface Logger {
|
|
4
|
+
debug: (message: string, ...args: any[]) => void;
|
|
5
|
+
info: (message: string, ...args: any[]) => void;
|
|
6
|
+
warn: (message: string, ...args: any[]) => void;
|
|
7
|
+
error: (message: string, ...args: any[]) => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
3
10
|
/**
|
|
4
11
|
* @file src/types.ts
|
|
5
12
|
* @description This file serves as the central source for all data types and interfaces
|
|
@@ -192,25 +199,11 @@ interface RefreshTokenConfig {
|
|
|
192
199
|
* 'error': Logs only critical errors.
|
|
193
200
|
* 'silent': Disables all logging.
|
|
194
201
|
*/
|
|
195
|
-
type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent'
|
|
202
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
196
203
|
/**
|
|
197
204
|
* An interface for a custom logger, compatible with the standard `console` object.
|
|
198
205
|
* It now includes a `debug` method for more granular logging.
|
|
199
206
|
*/
|
|
200
|
-
interface Logger {
|
|
201
|
-
/** Logs a standard message. In our wrapper, this is often an alias for `info` or `debug`. */
|
|
202
|
-
log(message?: any, ...optionalParams: any[]): void;
|
|
203
|
-
/** Logs an informational message. */
|
|
204
|
-
info(message?: any, ...optionalParams: any[]): void;
|
|
205
|
-
/** Logs a warning message. */
|
|
206
|
-
warn(message?: any, ...optionalParams: any[]): void;
|
|
207
|
-
/** Logs an error message. */
|
|
208
|
-
error(message?: any, ...optionalParams: any[]): void;
|
|
209
|
-
/**
|
|
210
|
-
* Logs a debug message, typically for verbose, development-only output.
|
|
211
|
-
*/
|
|
212
|
-
debug(message?: any, ...optionalParams: any[]): void;
|
|
213
|
-
}
|
|
214
207
|
/**
|
|
215
208
|
* The main configuration object for the `createApiClient` factory function.
|
|
216
209
|
*/
|
|
@@ -248,17 +241,6 @@ interface ApiClientConfig {
|
|
|
248
241
|
maxQueueSize?: number;
|
|
249
242
|
}
|
|
250
243
|
|
|
251
|
-
/**
|
|
252
|
-
* @file src/core/client.ts
|
|
253
|
-
* @description This is the heart of the API client library.
|
|
254
|
-
* The `createApiClient` function constructs and configures a sophisticated Axios instance.
|
|
255
|
-
* It features intelligent, security-first token management, a flexible middleware system,
|
|
256
|
-
* and customizable logging, all designed to work seamlessly in modern web frameworks like Next.js.
|
|
257
|
-
*/
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Creates and configures a new Axios instance with advanced features.
|
|
261
|
-
*/
|
|
262
244
|
declare function createApiClient(config: ApiClientConfig): AxiosInstance;
|
|
263
245
|
|
|
264
246
|
/**
|
|
@@ -472,11 +454,6 @@ type ModuleActions<TModule extends ApiModuleConfig> = {
|
|
|
472
454
|
[K in keyof TModule['actions']]: TModule['actions'][K] extends ActionConfig<infer TInput, infer TOutput> ? ExecutableAction<TInput, TOutput> : never;
|
|
473
455
|
};
|
|
474
456
|
|
|
475
|
-
/**
|
|
476
|
-
* A factory function to create a reusable set of API services for a specific endpoint.
|
|
477
|
-
* It provides full CRUD operations plus advanced features like bulk deletion and file uploads,
|
|
478
|
-
* with intelligent, dynamic URL building.
|
|
479
|
-
*/
|
|
480
457
|
declare function createApiServices<T>(axiosInstance: AxiosInstance, baseEndpoint: string): {
|
|
481
458
|
get: (id?: string | number, config?: ActionOptions) => Promise<StandardResponse<T>>;
|
|
482
459
|
getWithQuery: (query: string, config?: RequestConfig) => Promise<StandardResponse<T>>;
|
|
@@ -563,15 +540,6 @@ declare class CacheManager {
|
|
|
563
540
|
}
|
|
564
541
|
declare const cacheManager: CacheManager;
|
|
565
542
|
|
|
566
|
-
/**
|
|
567
|
-
* A smart response processor that normalizes API responses.
|
|
568
|
-
* It intelligently unwraps nested data from standard API envelopes
|
|
569
|
-
* (like { success: true, data: {...} }) and provides direct access
|
|
570
|
-
* to the core data, while still handling errors consistently.
|
|
571
|
-
*
|
|
572
|
-
* @param responseOrError The raw Axios response or a pre-processed ApiError.
|
|
573
|
-
* @returns A standardized `StandardResponse` object with direct access to `.data`.
|
|
574
|
-
*/
|
|
575
543
|
declare const processResponse: <T>(responseOrError: AxiosResponse<any> | ApiError) => StandardResponse<T>;
|
|
576
544
|
|
|
577
545
|
declare function useApi<T>(axiosInstance: AxiosInstance, config: UseApiConfig<T>): UseApiReturn<T>;
|
|
@@ -629,4 +597,4 @@ interface UseApiResourceReturn<T, TCreate, TUpdate, TPathParams> {
|
|
|
629
597
|
setQuery: React.Dispatch<React.SetStateAction<QueryOptions>>;
|
|
630
598
|
}
|
|
631
599
|
|
|
632
|
-
export { type ActionConfig, type ActionOptions, type ActionState, type ApiClientConfig, type ApiError, type ApiModuleConfig, type ApiResourceStatus, type ApiResponse, type ExecutableAction, type LogLevel, type
|
|
600
|
+
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 PaginationMeta, type QueryOptions, type RefreshTokenConfig, type RequestConfig, type StandardResponse, type TokenManager, type Tokens, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { InternalAxiosRequestConfig, AxiosResponse, AxiosRequestConfig, AxiosProgressEvent, AxiosInstance, Method } from 'axios';
|
|
2
2
|
|
|
3
|
+
interface Logger {
|
|
4
|
+
debug: (message: string, ...args: any[]) => void;
|
|
5
|
+
info: (message: string, ...args: any[]) => void;
|
|
6
|
+
warn: (message: string, ...args: any[]) => void;
|
|
7
|
+
error: (message: string, ...args: any[]) => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
3
10
|
/**
|
|
4
11
|
* @file src/types.ts
|
|
5
12
|
* @description This file serves as the central source for all data types and interfaces
|
|
@@ -192,25 +199,11 @@ interface RefreshTokenConfig {
|
|
|
192
199
|
* 'error': Logs only critical errors.
|
|
193
200
|
* 'silent': Disables all logging.
|
|
194
201
|
*/
|
|
195
|
-
type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent'
|
|
202
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
196
203
|
/**
|
|
197
204
|
* An interface for a custom logger, compatible with the standard `console` object.
|
|
198
205
|
* It now includes a `debug` method for more granular logging.
|
|
199
206
|
*/
|
|
200
|
-
interface Logger {
|
|
201
|
-
/** Logs a standard message. In our wrapper, this is often an alias for `info` or `debug`. */
|
|
202
|
-
log(message?: any, ...optionalParams: any[]): void;
|
|
203
|
-
/** Logs an informational message. */
|
|
204
|
-
info(message?: any, ...optionalParams: any[]): void;
|
|
205
|
-
/** Logs a warning message. */
|
|
206
|
-
warn(message?: any, ...optionalParams: any[]): void;
|
|
207
|
-
/** Logs an error message. */
|
|
208
|
-
error(message?: any, ...optionalParams: any[]): void;
|
|
209
|
-
/**
|
|
210
|
-
* Logs a debug message, typically for verbose, development-only output.
|
|
211
|
-
*/
|
|
212
|
-
debug(message?: any, ...optionalParams: any[]): void;
|
|
213
|
-
}
|
|
214
207
|
/**
|
|
215
208
|
* The main configuration object for the `createApiClient` factory function.
|
|
216
209
|
*/
|
|
@@ -248,17 +241,6 @@ interface ApiClientConfig {
|
|
|
248
241
|
maxQueueSize?: number;
|
|
249
242
|
}
|
|
250
243
|
|
|
251
|
-
/**
|
|
252
|
-
* @file src/core/client.ts
|
|
253
|
-
* @description This is the heart of the API client library.
|
|
254
|
-
* The `createApiClient` function constructs and configures a sophisticated Axios instance.
|
|
255
|
-
* It features intelligent, security-first token management, a flexible middleware system,
|
|
256
|
-
* and customizable logging, all designed to work seamlessly in modern web frameworks like Next.js.
|
|
257
|
-
*/
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Creates and configures a new Axios instance with advanced features.
|
|
261
|
-
*/
|
|
262
244
|
declare function createApiClient(config: ApiClientConfig): AxiosInstance;
|
|
263
245
|
|
|
264
246
|
/**
|
|
@@ -472,11 +454,6 @@ type ModuleActions<TModule extends ApiModuleConfig> = {
|
|
|
472
454
|
[K in keyof TModule['actions']]: TModule['actions'][K] extends ActionConfig<infer TInput, infer TOutput> ? ExecutableAction<TInput, TOutput> : never;
|
|
473
455
|
};
|
|
474
456
|
|
|
475
|
-
/**
|
|
476
|
-
* A factory function to create a reusable set of API services for a specific endpoint.
|
|
477
|
-
* It provides full CRUD operations plus advanced features like bulk deletion and file uploads,
|
|
478
|
-
* with intelligent, dynamic URL building.
|
|
479
|
-
*/
|
|
480
457
|
declare function createApiServices<T>(axiosInstance: AxiosInstance, baseEndpoint: string): {
|
|
481
458
|
get: (id?: string | number, config?: ActionOptions) => Promise<StandardResponse<T>>;
|
|
482
459
|
getWithQuery: (query: string, config?: RequestConfig) => Promise<StandardResponse<T>>;
|
|
@@ -563,15 +540,6 @@ declare class CacheManager {
|
|
|
563
540
|
}
|
|
564
541
|
declare const cacheManager: CacheManager;
|
|
565
542
|
|
|
566
|
-
/**
|
|
567
|
-
* A smart response processor that normalizes API responses.
|
|
568
|
-
* It intelligently unwraps nested data from standard API envelopes
|
|
569
|
-
* (like { success: true, data: {...} }) and provides direct access
|
|
570
|
-
* to the core data, while still handling errors consistently.
|
|
571
|
-
*
|
|
572
|
-
* @param responseOrError The raw Axios response or a pre-processed ApiError.
|
|
573
|
-
* @returns A standardized `StandardResponse` object with direct access to `.data`.
|
|
574
|
-
*/
|
|
575
543
|
declare const processResponse: <T>(responseOrError: AxiosResponse<any> | ApiError) => StandardResponse<T>;
|
|
576
544
|
|
|
577
545
|
declare function useApi<T>(axiosInstance: AxiosInstance, config: UseApiConfig<T>): UseApiReturn<T>;
|
|
@@ -629,4 +597,4 @@ interface UseApiResourceReturn<T, TCreate, TUpdate, TPathParams> {
|
|
|
629
597
|
setQuery: React.Dispatch<React.SetStateAction<QueryOptions>>;
|
|
630
598
|
}
|
|
631
599
|
|
|
632
|
-
export { type ActionConfig, type ActionOptions, type ActionState, type ApiClientConfig, type ApiError, type ApiModuleConfig, type ApiResourceStatus, type ApiResponse, type ExecutableAction, type LogLevel, type
|
|
600
|
+
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 PaginationMeta, type QueryOptions, type RefreshTokenConfig, type RequestConfig, type StandardResponse, type TokenManager, type Tokens, 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 };
|