@next-feature/client 0.0.1
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 +7 -0
- package/components/api-error-boundary.d.ts +18 -0
- package/hooks/use-api-error.d.ts +10 -0
- package/index.d.ts +30 -0
- package/index.js +4831 -0
- package/lib/client.d.ts +68 -0
- package/lib/error.d.ts +35 -0
- package/lib/types/client.d.ts +19 -0
- package/lib/types/index.d.ts +27 -0
- package/lib/utils/axios.d.ts +7 -0
- package/lib/utils/error.d.ts +19 -0
- package/lib/utils/zod.d.ts +10 -0
- package/package.json +17 -0
- package/server.d.ts +0 -0
- package/server.js +1 -0
package/lib/client.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { ApiClientConfig } from './types/client';
|
|
3
|
+
/**
|
|
4
|
+
* Axios wrapper with JWT/Refresh token handling
|
|
5
|
+
*/
|
|
6
|
+
export declare class ApiClient {
|
|
7
|
+
private readonly instance;
|
|
8
|
+
private isRefreshing;
|
|
9
|
+
private pendingRequests;
|
|
10
|
+
private config;
|
|
11
|
+
constructor(config: ApiClientConfig);
|
|
12
|
+
/**
|
|
13
|
+
* Setup request and response interceptors
|
|
14
|
+
*/
|
|
15
|
+
private setupInterceptors;
|
|
16
|
+
/**
|
|
17
|
+
* Attach JWT token to request headers
|
|
18
|
+
*/
|
|
19
|
+
private handleRequestFulfilled;
|
|
20
|
+
/**
|
|
21
|
+
* Handle request errors
|
|
22
|
+
*/
|
|
23
|
+
private handleRequestRejected;
|
|
24
|
+
/**
|
|
25
|
+
* Pass through successful responses
|
|
26
|
+
*/
|
|
27
|
+
private handleResponseFulfilled;
|
|
28
|
+
/**
|
|
29
|
+
* Handle response errors with retry logic and token refresh
|
|
30
|
+
*/
|
|
31
|
+
private handleResponseRejected;
|
|
32
|
+
/**
|
|
33
|
+
* Handle 401 errors with token refresh
|
|
34
|
+
*/
|
|
35
|
+
private handleUnauthorizedError;
|
|
36
|
+
/**
|
|
37
|
+
* Refresh the JWT token using the refresh token
|
|
38
|
+
*/
|
|
39
|
+
private refreshToken;
|
|
40
|
+
/**
|
|
41
|
+
* Process all pending requests after token refresh
|
|
42
|
+
*/
|
|
43
|
+
private processPendingRequests;
|
|
44
|
+
/**
|
|
45
|
+
* Determine if request should be retried
|
|
46
|
+
*/
|
|
47
|
+
private shouldRetry;
|
|
48
|
+
/**
|
|
49
|
+
* Retry failed request with exponential backoff
|
|
50
|
+
*/
|
|
51
|
+
private retryRequest;
|
|
52
|
+
/**
|
|
53
|
+
* Sleep helper for retry delays
|
|
54
|
+
*/
|
|
55
|
+
private sleep;
|
|
56
|
+
/**
|
|
57
|
+
* HTTP Methods with proper typing
|
|
58
|
+
*/
|
|
59
|
+
get<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
|
|
60
|
+
post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
|
|
61
|
+
put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
|
|
62
|
+
patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
|
|
63
|
+
delete<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
|
|
64
|
+
/**
|
|
65
|
+
* Get the underlying Axios instance for advanced usage
|
|
66
|
+
*/
|
|
67
|
+
getAxiosInstance(): AxiosInstance;
|
|
68
|
+
}
|
package/lib/error.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { HttpStatusCode } from 'axios';
|
|
2
|
+
import { ProblemDetail } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Custom error class for API errors
|
|
5
|
+
*/
|
|
6
|
+
export declare class ApiError extends Error {
|
|
7
|
+
problemDetail: ProblemDetail;
|
|
8
|
+
originalError?: Error;
|
|
9
|
+
constructor(problemDetail: ProblemDetail, originalError?: Error);
|
|
10
|
+
get status(): HttpStatusCode;
|
|
11
|
+
get body(): ProblemDetail;
|
|
12
|
+
get isClientError(): boolean;
|
|
13
|
+
get isServerError(): boolean;
|
|
14
|
+
get isUnauthorized(): boolean;
|
|
15
|
+
get isForbidden(): boolean;
|
|
16
|
+
get isNotFound(): boolean;
|
|
17
|
+
static builder(): ApiErrorBuilder;
|
|
18
|
+
static of(error: Error | unknown): ApiError;
|
|
19
|
+
}
|
|
20
|
+
export declare class ApiErrorBuilder {
|
|
21
|
+
private _originalError;
|
|
22
|
+
private _problemDetail;
|
|
23
|
+
constructor(_originalError: Error | null);
|
|
24
|
+
/**
|
|
25
|
+
* Set standard ProblemDetail
|
|
26
|
+
*/
|
|
27
|
+
problemDetail(problemDetail: ProblemDetail): ApiErrorBuilder;
|
|
28
|
+
originalError(error: Error): ApiErrorBuilder;
|
|
29
|
+
message(msg: string): ApiErrorBuilder;
|
|
30
|
+
status(status: HttpStatusCode): ApiErrorBuilder;
|
|
31
|
+
errors(errors: Record<string, string>): ApiErrorBuilder;
|
|
32
|
+
title(title: string): ApiErrorBuilder;
|
|
33
|
+
instance(instance: string): ApiErrorBuilder;
|
|
34
|
+
build(): ApiError;
|
|
35
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { InternalAxiosRequestConfig } from 'axios';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for the API client
|
|
4
|
+
*
|
|
5
|
+
* [api-client-config]
|
|
6
|
+
* next-feature@0.1.1-beta.5
|
|
7
|
+
* January 11th 2026, 9:00:22 pm
|
|
8
|
+
*/
|
|
9
|
+
export interface ApiClientConfig {
|
|
10
|
+
baseURL: string;
|
|
11
|
+
timeout?: number;
|
|
12
|
+
enableRefreshToken?: boolean;
|
|
13
|
+
maxRetries?: number;
|
|
14
|
+
retryDelay?: number;
|
|
15
|
+
onAuthenticated?: (config: InternalAxiosRequestConfig) => void | Promise<void>;
|
|
16
|
+
onUnauthorized?: () => void | Promise<void>;
|
|
17
|
+
onRefreshTokenExpired?: () => void | Promise<void>;
|
|
18
|
+
onRefreshToken?: () => string | Promise<string>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { HttpStatusCode } from 'axios';
|
|
2
|
+
/**
|
|
3
|
+
* [api-response]
|
|
4
|
+
* next-feature@0.0.11-beta
|
|
5
|
+
* November 4th 2025, 6:37:27 pm
|
|
6
|
+
*/
|
|
7
|
+
export interface ApiResponse<Response> {
|
|
8
|
+
success?: boolean;
|
|
9
|
+
message?: string;
|
|
10
|
+
error?: ProblemDetail;
|
|
11
|
+
data: Response;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Spring Boot ProblemDetail structure
|
|
15
|
+
*
|
|
16
|
+
* [problem-detail]
|
|
17
|
+
* next-feature@0.1.1-beta.5
|
|
18
|
+
* January 11th 2026, 8:55:50 pm
|
|
19
|
+
*/
|
|
20
|
+
export interface ProblemDetail {
|
|
21
|
+
type: string;
|
|
22
|
+
title: string;
|
|
23
|
+
status: HttpStatusCode;
|
|
24
|
+
detail: string;
|
|
25
|
+
instance?: string;
|
|
26
|
+
errors?: Record<string, string>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ApiError } from '../error';
|
|
2
|
+
/**
|
|
3
|
+
* Extract user-friendly error message from ApiError
|
|
4
|
+
*
|
|
5
|
+
* [get-error-message]
|
|
6
|
+
* next-feature@0.0.11-beta
|
|
7
|
+
* November 4th 2025, 11:47:45 am
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
export declare function getErrorMessage(error: unknown): string;
|
|
11
|
+
/**
|
|
12
|
+
* Check if error is a specific HTTP status
|
|
13
|
+
*/
|
|
14
|
+
export declare function isHttpStatus(error: unknown, status: number): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Handle common API errors
|
|
17
|
+
*/
|
|
18
|
+
declare function handleApiError(error: unknown): ApiError;
|
|
19
|
+
export default handleApiError;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ZodError } from 'zod';
|
|
2
|
+
import { ApiError } from '../error';
|
|
3
|
+
/**
|
|
4
|
+
* Create ApiError from Zod validation error
|
|
5
|
+
*
|
|
6
|
+
* [handle-zod-error]
|
|
7
|
+
* next-feature@0.1.1-beta.5
|
|
8
|
+
* January 11th 2026, 9:40:46 pm
|
|
9
|
+
*/
|
|
10
|
+
export declare function handleZodError(zodError: ZodError): ApiError;
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@next-feature/client",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "./index.js",
|
|
5
|
+
"types": "./index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./index.mjs",
|
|
9
|
+
"require": "./index.js"
|
|
10
|
+
},
|
|
11
|
+
"./server": {
|
|
12
|
+
"types": "./dist/server.d.ts",
|
|
13
|
+
"import": "./dist/server.js",
|
|
14
|
+
"default": "./dist/server.js"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
package/server.d.ts
ADDED
|
File without changes
|
package/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|