@fjell/client-api 4.4.17 → 4.4.19
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/ClientApiOptions.d.ts +7 -0
- package/dist/errors/index.d.ts +150 -0
- package/dist/http/HttpWrapper.d.ts +61 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +718 -14
- package/dist/index.js.map +4 -4
- package/dist/ops/action.d.ts +2 -2
- package/dist/ops/all.d.ts +2 -2
- package/dist/ops/allAction.d.ts +2 -2
- package/dist/ops/allFacet.d.ts +2 -2
- package/dist/ops/create.d.ts +2 -2
- package/dist/ops/errorHandling.d.ts +27 -0
- package/dist/ops/facet.d.ts +2 -2
- package/dist/ops/find.d.ts +2 -2
- package/dist/ops/findOne.d.ts +2 -2
- package/dist/ops/get.d.ts +2 -2
- package/dist/ops/index.d.ts +3 -3
- package/dist/ops/one.d.ts +2 -2
- package/dist/ops/remove.d.ts +2 -2
- package/dist/ops/update.d.ts +2 -2
- package/package.json +1 -1
- package/vitest.config.ts +0 -6
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Item } from "@fjell/core";
|
|
2
2
|
import { ClientApi } from "./ClientApi";
|
|
3
3
|
import { DeleteMethodOptions, GetMethodOptions, PostMethodOptions, PutMethodOptions } from "@fjell/http-api";
|
|
4
|
+
import { RetryConfig } from "./http/HttpWrapper";
|
|
4
5
|
export interface ClientApiOptions {
|
|
5
6
|
readAuthenticated?: boolean;
|
|
6
7
|
allAuthenticated?: boolean;
|
|
@@ -10,4 +11,10 @@ export interface ClientApiOptions {
|
|
|
10
11
|
postOptions?: Partial<PostMethodOptions>;
|
|
11
12
|
putOptions?: Partial<PutMethodOptions>;
|
|
12
13
|
deleteOptions?: Partial<DeleteMethodOptions>;
|
|
14
|
+
/** Configuration for HTTP request retry behavior */
|
|
15
|
+
retryConfig?: RetryConfig;
|
|
16
|
+
/** Whether to enable comprehensive error handling and logging (default: true) */
|
|
17
|
+
enableErrorHandling?: boolean;
|
|
18
|
+
/** Custom error handler for additional error processing */
|
|
19
|
+
errorHandler?: (error: any, context?: Record<string, any>) => void;
|
|
13
20
|
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for all Client API errors
|
|
3
|
+
*/
|
|
4
|
+
export declare abstract class ClientApiError extends Error {
|
|
5
|
+
abstract readonly code: string;
|
|
6
|
+
abstract readonly isRetryable: boolean;
|
|
7
|
+
readonly timestamp: Date;
|
|
8
|
+
readonly context?: Record<string, any>;
|
|
9
|
+
constructor(message: string, context?: Record<string, any>);
|
|
10
|
+
toJSON(): {
|
|
11
|
+
name: string;
|
|
12
|
+
code: string;
|
|
13
|
+
message: string;
|
|
14
|
+
isRetryable: boolean;
|
|
15
|
+
timestamp: Date;
|
|
16
|
+
context: Record<string, any> | undefined;
|
|
17
|
+
stack: string | undefined;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Network-related errors (connection issues, timeouts)
|
|
22
|
+
*/
|
|
23
|
+
export declare class NetworkError extends ClientApiError {
|
|
24
|
+
readonly code = "NETWORK_ERROR";
|
|
25
|
+
readonly isRetryable = true;
|
|
26
|
+
constructor(message: string, context?: Record<string, any>);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* HTTP timeout errors
|
|
30
|
+
*/
|
|
31
|
+
export declare class TimeoutError extends ClientApiError {
|
|
32
|
+
readonly code = "TIMEOUT_ERROR";
|
|
33
|
+
readonly isRetryable = true;
|
|
34
|
+
constructor(timeout: number, context?: Record<string, any>);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Authentication errors (401 Unauthorized)
|
|
38
|
+
*/
|
|
39
|
+
export declare class AuthenticationError extends ClientApiError {
|
|
40
|
+
readonly code = "AUTHENTICATION_ERROR";
|
|
41
|
+
readonly isRetryable = false;
|
|
42
|
+
constructor(message?: string, context?: Record<string, any>);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Authorization errors (403 Forbidden)
|
|
46
|
+
*/
|
|
47
|
+
export declare class AuthorizationError extends ClientApiError {
|
|
48
|
+
readonly code = "AUTHORIZATION_ERROR";
|
|
49
|
+
readonly isRetryable = false;
|
|
50
|
+
constructor(message?: string, context?: Record<string, any>);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Resource not found errors (404 Not Found)
|
|
54
|
+
*/
|
|
55
|
+
export declare class NotFoundError extends ClientApiError {
|
|
56
|
+
readonly code = "NOT_FOUND_ERROR";
|
|
57
|
+
readonly isRetryable = false;
|
|
58
|
+
constructor(resource: string, identifier?: string, context?: Record<string, any>);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Request validation errors (400 Bad Request)
|
|
62
|
+
*/
|
|
63
|
+
export declare class ValidationError extends ClientApiError {
|
|
64
|
+
readonly code = "VALIDATION_ERROR";
|
|
65
|
+
readonly isRetryable = false;
|
|
66
|
+
readonly validationErrors?: Array<{
|
|
67
|
+
field: string;
|
|
68
|
+
message: string;
|
|
69
|
+
}>;
|
|
70
|
+
constructor(message: string, validationErrors?: Array<{
|
|
71
|
+
field: string;
|
|
72
|
+
message: string;
|
|
73
|
+
}>, context?: Record<string, any>);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Conflict errors (409 Conflict)
|
|
77
|
+
*/
|
|
78
|
+
export declare class ConflictError extends ClientApiError {
|
|
79
|
+
readonly code = "CONFLICT_ERROR";
|
|
80
|
+
readonly isRetryable = false;
|
|
81
|
+
constructor(message: string, context?: Record<string, any>);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Rate limiting errors (429 Too Many Requests)
|
|
85
|
+
*/
|
|
86
|
+
export declare class RateLimitError extends ClientApiError {
|
|
87
|
+
readonly code = "RATE_LIMIT_ERROR";
|
|
88
|
+
readonly isRetryable = true;
|
|
89
|
+
readonly retryAfter?: number;
|
|
90
|
+
constructor(retryAfter?: number, context?: Record<string, any>);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Server errors (5xx status codes)
|
|
94
|
+
*/
|
|
95
|
+
export declare class ServerError extends ClientApiError {
|
|
96
|
+
readonly code = "SERVER_ERROR";
|
|
97
|
+
readonly isRetryable = true;
|
|
98
|
+
readonly statusCode: number;
|
|
99
|
+
constructor(statusCode: number, message?: string, context?: Record<string, any>);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Request payload too large errors (413)
|
|
103
|
+
*/
|
|
104
|
+
export declare class PayloadTooLargeError extends ClientApiError {
|
|
105
|
+
readonly code = "PAYLOAD_TOO_LARGE_ERROR";
|
|
106
|
+
readonly isRetryable = false;
|
|
107
|
+
constructor(maxSize?: string, context?: Record<string, any>);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Generic HTTP errors for unhandled status codes
|
|
111
|
+
*/
|
|
112
|
+
export declare class HttpError extends ClientApiError {
|
|
113
|
+
readonly code = "HTTP_ERROR";
|
|
114
|
+
readonly isRetryable: boolean;
|
|
115
|
+
readonly statusCode: number;
|
|
116
|
+
readonly statusText: string;
|
|
117
|
+
constructor(statusCode: number, statusText: string, message?: string, context?: Record<string, any>);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Configuration errors
|
|
121
|
+
*/
|
|
122
|
+
export declare class ConfigurationError extends ClientApiError {
|
|
123
|
+
readonly code = "CONFIGURATION_ERROR";
|
|
124
|
+
readonly isRetryable = false;
|
|
125
|
+
constructor(message: string, context?: Record<string, any>);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Parse/serialization errors
|
|
129
|
+
*/
|
|
130
|
+
export declare class ParseError extends ClientApiError {
|
|
131
|
+
readonly code = "PARSE_ERROR";
|
|
132
|
+
readonly isRetryable = false;
|
|
133
|
+
constructor(message: string, context?: Record<string, any>);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Create appropriate error from HTTP response
|
|
137
|
+
*/
|
|
138
|
+
export declare function createHttpError(statusCode: number, statusText: string, responseBody?: any, context?: Record<string, any>): ClientApiError;
|
|
139
|
+
/**
|
|
140
|
+
* Create appropriate error from network/connection issues
|
|
141
|
+
*/
|
|
142
|
+
export declare function createNetworkError(error: any, context?: Record<string, any>): ClientApiError;
|
|
143
|
+
/**
|
|
144
|
+
* Type guard to check if error is retryable
|
|
145
|
+
*/
|
|
146
|
+
export declare function isRetryableError(error: any): boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Type guard to check if error is a Client API error
|
|
149
|
+
*/
|
|
150
|
+
export declare function isClientApiError(error: any): error is ClientApiError;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { HttpApi } from '@fjell/http-api';
|
|
2
|
+
import { ClientApiError } from '../errors/index';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for retry behavior
|
|
5
|
+
*/
|
|
6
|
+
export interface RetryConfig {
|
|
7
|
+
/** Maximum number of retry attempts (default: 3) */
|
|
8
|
+
maxRetries?: number;
|
|
9
|
+
/** Initial delay between retries in milliseconds (default: 1000) */
|
|
10
|
+
initialDelayMs?: number;
|
|
11
|
+
/** Maximum delay between retries in milliseconds (default: 30000) */
|
|
12
|
+
maxDelayMs?: number;
|
|
13
|
+
/** Backoff multiplier for exponential backoff (default: 2) */
|
|
14
|
+
backoffMultiplier?: number;
|
|
15
|
+
/** Whether to add jitter to retry delays (default: true) */
|
|
16
|
+
enableJitter?: boolean;
|
|
17
|
+
/** Custom function to determine if an error should be retried */
|
|
18
|
+
shouldRetry?: (error: ClientApiError, attemptNumber: number) => boolean;
|
|
19
|
+
/** Called before each retry attempt */
|
|
20
|
+
onRetry?: (error: ClientApiError, attemptNumber: number, delay: number) => void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Enhanced HTTP wrapper with retry logic and comprehensive error handling
|
|
24
|
+
*/
|
|
25
|
+
export declare class HttpWrapper {
|
|
26
|
+
private readonly api;
|
|
27
|
+
private readonly retryConfig;
|
|
28
|
+
constructor(api: HttpApi, retryConfig?: RetryConfig);
|
|
29
|
+
/**
|
|
30
|
+
* Execute HTTP operation with retry logic and error handling
|
|
31
|
+
*/
|
|
32
|
+
executeWithRetry<T>(operation: () => Promise<T>, operationName: string, context?: Record<string, any>): Promise<T>;
|
|
33
|
+
/**
|
|
34
|
+
* Convert any error to a ClientApiError
|
|
35
|
+
*/
|
|
36
|
+
private convertToClientApiError;
|
|
37
|
+
/**
|
|
38
|
+
* Wrapper for HTTP GET operations
|
|
39
|
+
*/
|
|
40
|
+
get<T>(url: string, options?: any, context?: Record<string, any>): Promise<T>;
|
|
41
|
+
/**
|
|
42
|
+
* Wrapper for HTTP POST operations
|
|
43
|
+
*/
|
|
44
|
+
post<T>(url: string, data?: any, options?: any, context?: Record<string, any>): Promise<T>;
|
|
45
|
+
/**
|
|
46
|
+
* Wrapper for HTTP PUT operations
|
|
47
|
+
*/
|
|
48
|
+
put<T>(url: string, data?: any, options?: any, context?: Record<string, any>): Promise<T>;
|
|
49
|
+
/**
|
|
50
|
+
* Wrapper for HTTP DELETE operations
|
|
51
|
+
*/
|
|
52
|
+
delete<T>(url: string, options?: any, context?: Record<string, any>): Promise<T>;
|
|
53
|
+
/**
|
|
54
|
+
* Update retry configuration
|
|
55
|
+
*/
|
|
56
|
+
updateRetryConfig(newConfig: Partial<RetryConfig>): void;
|
|
57
|
+
/**
|
|
58
|
+
* Get current retry configuration
|
|
59
|
+
*/
|
|
60
|
+
getRetryConfig(): Required<RetryConfig>;
|
|
61
|
+
}
|
package/dist/index.d.ts
CHANGED