@tapsilat/tapsilat-js 1.0.3 → 1.0.4

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,7 +1,14 @@
1
- import { TapsilatConfig, APIResponse } from "../types";
1
+ /**
2
+ * @category HTTP
3
+ * @module HttpClient
4
+ */
5
+ import { TapsilatConfig, APIResponse } from "../types/index";
2
6
  import { InterceptorManager } from "./interceptors";
3
7
  /**
4
- * Configuration options for individual HTTP requests
8
+ * @category HTTP
9
+ * @summary Configuration options for individual HTTP requests
10
+ * @description Extends RequestInit with additional Tapsilat-specific options for HTTP requests
11
+ * @interface RequestConfig
5
12
  */
6
13
  export interface RequestConfig extends Omit<RequestInit, "method" | "body"> {
7
14
  timeout?: number;
@@ -11,16 +18,24 @@ export interface RequestConfig extends Omit<RequestInit, "method" | "body"> {
11
18
  params?: Record<string, any>;
12
19
  }
13
20
  /**
14
- * HTTP methods supported by the client
21
+ * @category HTTP
22
+ * @summary HTTP methods supported by the client
23
+ * @description The standard HTTP methods available for API requests
24
+ * @typedef {string} HttpMethod
15
25
  */
16
26
  export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
17
27
  /**
18
- * Generic constraint for request body types
28
+ * @category HTTP
29
+ * @summary Generic constraint for request body types
30
+ * @description Types that can be sent as HTTP request bodies
31
+ * @typedef {object|array|string|FormData} RequestBody
19
32
  */
20
33
  export type RequestBody = Record<string, unknown> | Record<string, any> | object | unknown[] | string | FormData;
21
34
  /**
22
- * HTTP Client for making API requests with comprehensive error handling,
23
- * retry logic, and request/response interceptors
35
+ * @category HTTP
36
+ * @summary HTTP Client for making API requests to Tapsilat services
37
+ * @description Provides a robust client with comprehensive error handling,
38
+ * retry logic, and request/response interceptors for interacting with the Tapsilat API
24
39
  *
25
40
  * @example
26
41
  * ```typescript
@@ -31,41 +46,55 @@ export type RequestBody = Record<string, unknown> | Record<string, any> | object
31
46
  *
32
47
  * const data = await client.get<UserResponse>('/users/123');
33
48
  * ```
49
+ * @class HttpClient
34
50
  */
35
51
  export declare class HttpClient {
36
52
  private readonly config;
37
53
  private readonly interceptors;
54
+ /**
55
+ * @summary Creates a new HTTP client instance
56
+ * @description Initializes the HTTP client with the provided configuration
57
+ *
58
+ * @param config - The configuration for the Tapsilat API client
59
+ */
38
60
  constructor(config: TapsilatConfig);
39
61
  /**
40
- * GET request method overloads
62
+ * @summary Performs GET requests to the API
63
+ * @description Makes HTTP GET requests to retrieve data from the API
41
64
  */
42
65
  get<T = unknown>(url: string): Promise<APIResponse<T>>;
43
66
  get<T = unknown>(url: string, config: RequestConfig): Promise<APIResponse<T>>;
44
67
  /**
45
- * POST request method overloads
68
+ * @summary Performs POST requests to the API
69
+ * @description Makes HTTP POST requests to send data to the API
46
70
  */
47
71
  post<T = unknown>(url: string): Promise<APIResponse<T>>;
48
72
  post<T = unknown>(url: string, body: RequestBody): Promise<APIResponse<T>>;
49
73
  post<T = unknown>(url: string, body: RequestBody, config: RequestConfig): Promise<APIResponse<T>>;
50
74
  /**
51
- * PUT request method overloads
75
+ * @summary Performs PUT requests to the API
76
+ * @description Makes HTTP PUT requests to update entire resources in the API
52
77
  */
53
78
  put<T = unknown>(url: string): Promise<APIResponse<T>>;
54
79
  put<T = unknown>(url: string, body: RequestBody): Promise<APIResponse<T>>;
55
80
  put<T = unknown>(url: string, body: RequestBody, config: RequestConfig): Promise<APIResponse<T>>;
56
81
  /**
57
- * PATCH request method overloads
82
+ * @summary Performs PATCH requests to the API
83
+ * @description Makes HTTP PATCH requests to update parts of resources in the API
58
84
  */
59
85
  patch<T = unknown>(url: string): Promise<APIResponse<T>>;
60
86
  patch<T = unknown>(url: string, body: RequestBody): Promise<APIResponse<T>>;
61
87
  patch<T = unknown>(url: string, body: RequestBody, config: RequestConfig): Promise<APIResponse<T>>;
62
88
  /**
63
- * DELETE request method overloads
89
+ * @summary Performs DELETE requests to the API
90
+ * @description Makes HTTP DELETE requests to remove resources from the API
64
91
  */
65
92
  delete<T = unknown>(url: string): Promise<APIResponse<T>>;
66
93
  delete<T = unknown>(url: string, config: RequestConfig): Promise<APIResponse<T>>;
67
94
  /**
68
- * Core request method with comprehensive error handling and retry logic
95
+ * @category HTTP Client
96
+ * @summary Core request method with comprehensive error handling and retry logic
97
+ * @description Handles all HTTP requests with error handling, retries, and interceptors
69
98
  *
70
99
  * @param method - HTTP method to use
71
100
  * @param url - Request URL (relative to baseURL)
@@ -75,71 +104,141 @@ export declare class HttpClient {
75
104
  */
76
105
  private request;
77
106
  /**
78
- * Makes the actual HTTP request with timeout handling
107
+ * @category HTTP Client Internals
108
+ * @summary Makes the actual HTTP request with timeout handling
109
+ * @description Performs the fetch request with timeout handling and abort controller
110
+ *
111
+ * @param url - Full URL to request
112
+ * @param options - Fetch request options
113
+ * @param timeout - Optional timeout in milliseconds
114
+ * @returns Promise resolving to API response
79
115
  */
80
116
  private makeRequest;
81
117
  /**
82
- * Processes the fetch response and converts to APIResponse format
118
+ * @category HTTP Client Internals
119
+ * @summary Processes the fetch response and converts to APIResponse format
120
+ * @description Parses the response and formats it according to the APIResponse interface
121
+ *
122
+ * @param response - The raw fetch Response object
123
+ * @returns Processed API response
83
124
  */
84
125
  private processResponse;
85
126
  /**
86
- * Creates appropriate error based on response status and data
127
+ * @category HTTP Client Internals
128
+ * @summary Creates appropriate error based on response status and data
129
+ * @description Maps HTTP status codes to specific Tapsilat error types
130
+ *
131
+ * @param response - The raw fetch Response object
132
+ * @param data - The parsed response data
133
+ * @returns Appropriate TapsilatError subclass instance
87
134
  */
88
135
  private createErrorFromResponse;
89
136
  /**
90
- * Extracts error message from response data
137
+ * @category HTTP Client Internals
138
+ * @summary Extracts error message from response data
139
+ * @description Attempts to find an error message in various locations within the response
140
+ *
141
+ * @param data - The parsed response data
142
+ * @returns Error message if found
91
143
  */
92
144
  private extractErrorMessage;
93
145
  /**
94
- * Extracts validation details from error response
146
+ * @category HTTP Client Internals
147
+ * @summary Extracts validation details from error response
148
+ * @description Parses field-specific validation errors from the API response
149
+ *
150
+ * @param data - The parsed response data
151
+ * @returns Object mapping field names to error messages
95
152
  */
96
153
  private extractValidationDetails;
97
154
  /**
98
- * Extracts rate limit information from response headers
155
+ * @category HTTP Client Internals
156
+ * @summary Extracts rate limit information from response headers
157
+ * @description Reads and parses rate limiting headers from the API response
158
+ *
159
+ * @param response - The raw fetch Response object
160
+ * @returns Rate limit information including limits and reset time
99
161
  */
100
162
  private extractRateLimitInfo;
101
163
  /**
102
- * Builds the complete URL for the request
164
+ * @category HTTP Client Internals
165
+ * @summary Builds the complete URL for the request
166
+ * @description Constructs the full URL with base URL and query parameters
167
+ *
168
+ * @param url - The endpoint path or full URL
169
+ * @param customBaseURL - Optional override for the base URL
170
+ * @param params - Optional query parameters
171
+ * @returns Complete request URL
103
172
  */
104
173
  private buildUrl;
105
174
  /**
106
- * Builds RequestInit options for the fetch request
175
+ * @category HTTP Client Internals
176
+ * @summary Builds RequestInit options for the fetch request
177
+ * @description Prepares headers and request configuration for fetch API
178
+ *
179
+ * @param method - The HTTP method to use
180
+ * @param body - Optional request body
181
+ * @param config - Additional request configuration
182
+ * @returns Configured RequestInit object for fetch
107
183
  */
108
184
  private buildRequestOptions;
109
185
  /**
110
- * Determines if an error should prevent retrying
186
+ * @category HTTP Client Internals
187
+ * @summary Determines if an error should prevent retrying
188
+ * @description Checks error types to decide if retry attempts should be aborted
189
+ *
190
+ * @param error - The error that occurred
191
+ * @returns Whether retry should be prevented for this error
111
192
  */
112
193
  private shouldNotRetry;
113
194
  /**
114
- * Calculates retry delay with exponential backoff
195
+ * @category HTTP Client Internals
196
+ * @summary Calculates retry delay with exponential backoff
197
+ * @description Implements exponential backoff with jitter for retry attempts
198
+ *
199
+ * @param attempt - The current retry attempt number (0-indexed)
200
+ * @returns Delay in milliseconds before next retry
115
201
  */
116
202
  private calculateRetryDelay;
117
203
  /**
118
- * Utility method to create delay
204
+ * @category HTTP Client Internals
205
+ * @summary Utility method to create delay
206
+ * @description Creates a promise that resolves after the specified time
207
+ *
208
+ * @param ms - Delay time in milliseconds
209
+ * @returns Promise that resolves after the delay
119
210
  */
120
211
  private delay;
121
212
  /**
122
- * Gets the interceptor manager for advanced request/response handling
213
+ * @category Interceptors
214
+ * @summary Gets the interceptor manager for advanced request/response handling
215
+ * @description Provides access to the internal interceptor manager for custom handling
123
216
  *
124
217
  * @returns InterceptorManager instance
125
218
  */
126
219
  getInterceptors(): InterceptorManager;
127
220
  /**
128
- * Adds a request interceptor
221
+ * @category Interceptors
222
+ * @summary Adds a request interceptor
223
+ * @description Registers a function to intercept and modify requests before they are sent
129
224
  *
130
225
  * @param interceptor - Request interceptor function
131
226
  * @returns Interceptor ID for removal
132
227
  */
133
228
  addRequestInterceptor(interceptor: Parameters<InterceptorManager["addRequestInterceptor"]>[0]): number;
134
229
  /**
135
- * Adds a response interceptor
230
+ * @category Interceptors
231
+ * @summary Adds a response interceptor
232
+ * @description Registers a function to intercept and modify responses before they are returned
136
233
  *
137
234
  * @param interceptor - Response interceptor function
138
235
  * @returns Interceptor ID for removal
139
236
  */
140
237
  addResponseInterceptor(interceptor: Parameters<InterceptorManager["addResponseInterceptor"]>[0]): number;
141
238
  /**
142
- * Adds an error interceptor
239
+ * @category Interceptors
240
+ * @summary Adds an error interceptor
241
+ * @description Registers a function to intercept and potentially recover from errors
143
242
  *
144
243
  * @param interceptor - Error interceptor function
145
244
  * @returns Interceptor ID for removal
@@ -1 +1 @@
1
- {"version":3,"file":"HttpClient.d.ts","sourceRoot":"","sources":["../../src/http/HttpClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAQvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,aAAc,SAAQ,IAAI,CAAC,WAAW,EAAE,QAAQ,GAAG,MAAM,CAAC;IACzE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,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AUhC;;;;;;;OAOG;IACH,OAAO,CAAC,oBAAoB;IAgB5B;;;;;;;;;OASG;IACH,OAAO,CAAC,QAAQ;IAoChB;;;;;;;;;OASG;YACW,mBAAmB;IAuCjC;;;;;;;OAOG;IACH,OAAO,CAAC,cAAc;IAStB;;;;;;;OAOG;IACH,OAAO,CAAC,mBAAmB;IAS3B;;;;;;;OAOG;IACH,OAAO,CAAC,KAAK;IAMb;;;;;;OAMG;IACH,eAAe,IAAI,kBAAkB;IAIrC;;;;;;;OAOG;IACH,qBAAqB,CACnB,WAAW,EAAE,UAAU,CAAC,kBAAkB,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC,GACtE,MAAM;IAIT;;;;;;;OAOG;IACH,sBAAsB,CACpB,WAAW,EAAE,UAAU,CAAC,kBAAkB,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC,GACvE,MAAM;IAIT;;;;;;;OAOG;IACH,mBAAmB,CACjB,WAAW,EAAE,UAAU,CAAC,kBAAkB,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC,GACpE,MAAM;CAGV"}
@@ -1,4 +1,14 @@
1
- import { APIResponse } from "../types";
1
+ /**
2
+ * @category HTTP
3
+ * @module Interceptors
4
+ */
5
+ import { APIResponse } from "../types/index";
6
+ /**
7
+ * @category Interceptors
8
+ * @summary Function type for modifying HTTP requests before they are sent
9
+ * @description Allows preprocessing of URL and request options before the API call is made
10
+ * @typedef {Function} RequestInterceptor
11
+ */
2
12
  export type RequestInterceptor = (url: string, options: RequestInit) => Promise<{
3
13
  url: string;
4
14
  options: RequestInit;
@@ -6,43 +16,149 @@ export type RequestInterceptor = (url: string, options: RequestInit) => Promise<
6
16
  url: string;
7
17
  options: RequestInit;
8
18
  };
19
+ /**
20
+ * @category Interceptors
21
+ * @summary Function type for processing HTTP responses before returning to caller
22
+ * @description Allows transformation and analysis of API responses after receiving them but before they reach the calling code
23
+ * @typedef {Function} ResponseInterceptor
24
+ */
9
25
  export type ResponseInterceptor = (response: APIResponse<any>, request: {
10
26
  url: string;
11
27
  options: RequestInit;
12
28
  }) => Promise<APIResponse<any>> | APIResponse<any>;
29
+ /**
30
+ * @category Interceptors
31
+ * @summary Function type for handling errors that occur during HTTP requests
32
+ * @description Provides opportunity to recover from errors, transform them, or perform logging operations before they propagate
33
+ * @typedef {Function} ErrorInterceptor
34
+ */
13
35
  export type ErrorInterceptor = (error: Error, request: {
14
36
  url: string;
15
37
  options: RequestInit;
16
38
  }) => Promise<never | APIResponse<any>> | never | APIResponse<any>;
39
+ /**
40
+ * @category HTTP
41
+ * @summary Central registry and execution engine for all HTTP interceptors
42
+ * @description Maintains lists of request, response and error interceptors and provides methods to execute them in sequence
43
+ * @class InterceptorManager
44
+ */
17
45
  export declare class InterceptorManager {
18
46
  private requestInterceptors;
19
47
  private responseInterceptors;
20
48
  private errorInterceptors;
49
+ /**
50
+ * Adds a request interceptor to the chain
51
+ *
52
+ * @summary Register a new request interceptor function
53
+ * @description Adds a new interceptor to process requests before they are sent
54
+ *
55
+ * @param interceptor - The request interceptor function to add
56
+ * @returns The index of the added interceptor (can be used to remove it later)
57
+ */
21
58
  addRequestInterceptor(interceptor: RequestInterceptor): number;
59
+ /**
60
+ * Removes a previously added request interceptor
61
+ *
62
+ * @summary Unregister a request interceptor by its ID
63
+ * @description Removes the request interceptor at the specified position
64
+ *
65
+ * @param id - The index of the interceptor to remove
66
+ */
22
67
  removeRequestInterceptor(id: number): void;
68
+ /**
69
+ * Runs all registered request interceptors in sequence
70
+ *
71
+ * @summary Process a request through all interceptors
72
+ * @description Executes each registered request interceptor in order, passing modified url and options to each
73
+ *
74
+ * @param url - The initial request URL
75
+ * @param options - The initial request options
76
+ * @returns Modified URL and options after all interceptors have processed them
77
+ */
23
78
  executeRequestInterceptors(url: string, options: RequestInit): Promise<{
24
79
  url: string;
25
80
  options: RequestInit;
26
81
  }>;
82
+ /**
83
+ * @summary Register a new response interceptor function
84
+ * @description Adds a new interceptor to process responses before they are returned to the caller
85
+ *
86
+ * @param interceptor - The response interceptor function to add
87
+ * @returns The index of the added interceptor (can be used to remove it later)
88
+ */
27
89
  addResponseInterceptor(interceptor: ResponseInterceptor): number;
90
+ /**
91
+ * @summary Unregister a response interceptor by its ID
92
+ * @description Removes the response interceptor at the specified position
93
+ *
94
+ * @param id - The index of the interceptor to remove
95
+ */
28
96
  removeResponseInterceptor(id: number): void;
97
+ /**
98
+ * @summary Process a response through all interceptors
99
+ * @description Executes each registered response interceptor in order
100
+ *
101
+ * @param response - The API response to process
102
+ * @param request - The original request information
103
+ * @returns Modified response after all interceptors have processed it
104
+ */
29
105
  executeResponseInterceptors<T>(response: APIResponse<T>, request: {
30
106
  url: string;
31
107
  options: RequestInit;
32
108
  }): Promise<APIResponse<T>>;
109
+ /**
110
+ * @summary Register a new error interceptor function
111
+ * @description Adds a new interceptor to process errors before they are thrown
112
+ *
113
+ * @param interceptor - The error interceptor function to add
114
+ * @returns The index of the added interceptor (can be used to remove it later)
115
+ */
33
116
  addErrorInterceptor(interceptor: ErrorInterceptor): number;
117
+ /**
118
+ * @summary Unregister an error interceptor by its ID
119
+ * @description Removes the error interceptor at the specified position
120
+ *
121
+ * @param id - The index of the interceptor to remove
122
+ */
34
123
  removeErrorInterceptor(id: number): void;
124
+ /**
125
+ * @summary Process an error through all interceptors
126
+ * @description Executes each registered error interceptor in order until one handles the error
127
+ *
128
+ * @param error - The error that occurred during the request
129
+ * @param request - The original request information
130
+ * @returns Either a recovery response or throws the error if no interceptors handle it
131
+ */
35
132
  executeErrorInterceptors(error: Error, request: {
36
133
  url: string;
37
134
  options: RequestInit;
38
135
  }): Promise<never | APIResponse<any>>;
136
+ /**
137
+ * @summary Remove all registered interceptors
138
+ * @description Clears all request, response, and error interceptors at once
139
+ */
39
140
  clear(): void;
40
141
  }
142
+ /**
143
+ * @category Built-in Interceptors
144
+ * @summary Creates a set of interceptors for logging API requests, responses, and errors
145
+ * @description Provides detailed logging of HTTP activity when debug mode is enabled
146
+ *
147
+ * @param debug - When true, enables console logging of API activities
148
+ * @returns Object containing request, response, and error interceptors for logging
149
+ */
41
150
  export declare const createLoggingInterceptor: (debug?: boolean) => {
42
151
  request: RequestInterceptor;
43
152
  response: ResponseInterceptor;
44
153
  error: ErrorInterceptor;
45
154
  };
155
+ /**
156
+ * @category Built-in Interceptors
157
+ * @summary Creates interceptors for measuring API request/response times
158
+ * @description Tracks the duration of API calls and logs performance metrics
159
+ *
160
+ * @returns Object containing request and response interceptors for timing measurement
161
+ */
46
162
  export declare const createTimingInterceptor: () => {
47
163
  request: RequestInterceptor;
48
164
  response: ResponseInterceptor;
@@ -1 +1 @@
1
- {"version":3,"file":"interceptors.d.ts","sourceRoot":"","sources":["../../src/http/interceptors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,MAAM,kBAAkB,GAAG,CAC/B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,WAAW,KAElB,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,WAAW,CAAA;CAAE,CAAC,GAC9C;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,WAAW,CAAA;CAAE,CAAC;AAE1C,MAAM,MAAM,mBAAmB,GAAG,CAChC,QAAQ,EAAE,WAAW,CAAC,GAAG,CAAC,EAC1B,OAAO,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,WAAW,CAAA;CAAE,KAC3C,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;AAElD,MAAM,MAAM,gBAAgB,GAAG,CAC7B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,WAAW,CAAA;CAAE,KAC3C,OAAO,CAAC,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,GA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