@tapsilat/tapsilat-js 1.0.2
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/CHANGELOG.md +34 -0
- package/LICENSE +21 -0
- package/README.md +257 -0
- package/dist/TapsilatSDK.d.ts +293 -0
- package/dist/TapsilatSDK.d.ts.map +1 -0
- package/dist/errors/TapsilatError.d.ts +22 -0
- package/dist/errors/TapsilatError.d.ts.map +1 -0
- package/dist/http/HttpClient.d.ts +149 -0
- package/dist/http/HttpClient.d.ts.map +1 -0
- package/dist/http/interceptors.d.ts +50 -0
- package/dist/http/interceptors.d.ts.map +1 -0
- package/dist/index.d.ts +541 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +1118 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +1131 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +93 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types.d.ts +401 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/validators.d.ts +84 -0
- package/dist/utils/validators.d.ts.map +1 -0
- package/package.json +87 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { TapsilatConfig, APIResponse } from "../types";
|
|
2
|
+
import { InterceptorManager } from "./interceptors";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for individual HTTP requests
|
|
5
|
+
*/
|
|
6
|
+
export interface RequestConfig extends Omit<RequestInit, "method" | "body"> {
|
|
7
|
+
timeout?: number;
|
|
8
|
+
retries?: number;
|
|
9
|
+
baseURL?: string;
|
|
10
|
+
maxRetries?: number;
|
|
11
|
+
params?: Record<string, any>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* HTTP methods supported by the client
|
|
15
|
+
*/
|
|
16
|
+
export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
17
|
+
/**
|
|
18
|
+
* Generic constraint for request body types
|
|
19
|
+
*/
|
|
20
|
+
export type RequestBody = Record<string, unknown> | Record<string, any> | object | unknown[] | string | FormData;
|
|
21
|
+
/**
|
|
22
|
+
* HTTP Client for making API requests with comprehensive error handling,
|
|
23
|
+
* retry logic, and request/response interceptors
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const client = new HttpClient({
|
|
28
|
+
* apiKey: 'your-api-key',
|
|
29
|
+
* baseURL: 'https://api.example.com/v1'
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* const data = await client.get<UserResponse>('/users/123');
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare class HttpClient {
|
|
36
|
+
private readonly config;
|
|
37
|
+
private readonly interceptors;
|
|
38
|
+
constructor(config: TapsilatConfig);
|
|
39
|
+
/**
|
|
40
|
+
* GET request method overloads
|
|
41
|
+
*/
|
|
42
|
+
get<T = unknown>(url: string): Promise<APIResponse<T>>;
|
|
43
|
+
get<T = unknown>(url: string, config: RequestConfig): Promise<APIResponse<T>>;
|
|
44
|
+
/**
|
|
45
|
+
* POST request method overloads
|
|
46
|
+
*/
|
|
47
|
+
post<T = unknown>(url: string): Promise<APIResponse<T>>;
|
|
48
|
+
post<T = unknown>(url: string, body: RequestBody): Promise<APIResponse<T>>;
|
|
49
|
+
post<T = unknown>(url: string, body: RequestBody, config: RequestConfig): Promise<APIResponse<T>>;
|
|
50
|
+
/**
|
|
51
|
+
* PUT request method overloads
|
|
52
|
+
*/
|
|
53
|
+
put<T = unknown>(url: string): Promise<APIResponse<T>>;
|
|
54
|
+
put<T = unknown>(url: string, body: RequestBody): Promise<APIResponse<T>>;
|
|
55
|
+
put<T = unknown>(url: string, body: RequestBody, config: RequestConfig): Promise<APIResponse<T>>;
|
|
56
|
+
/**
|
|
57
|
+
* PATCH request method overloads
|
|
58
|
+
*/
|
|
59
|
+
patch<T = unknown>(url: string): Promise<APIResponse<T>>;
|
|
60
|
+
patch<T = unknown>(url: string, body: RequestBody): Promise<APIResponse<T>>;
|
|
61
|
+
patch<T = unknown>(url: string, body: RequestBody, config: RequestConfig): Promise<APIResponse<T>>;
|
|
62
|
+
/**
|
|
63
|
+
* DELETE request method overloads
|
|
64
|
+
*/
|
|
65
|
+
delete<T = unknown>(url: string): Promise<APIResponse<T>>;
|
|
66
|
+
delete<T = unknown>(url: string, config: RequestConfig): Promise<APIResponse<T>>;
|
|
67
|
+
/**
|
|
68
|
+
* Core request method with comprehensive error handling and retry logic
|
|
69
|
+
*
|
|
70
|
+
* @param method - HTTP method to use
|
|
71
|
+
* @param url - Request URL (relative to baseURL)
|
|
72
|
+
* @param body - Request body data
|
|
73
|
+
* @param config - Additional request configuration
|
|
74
|
+
* @returns Promise resolving to API response
|
|
75
|
+
*/
|
|
76
|
+
private request;
|
|
77
|
+
/**
|
|
78
|
+
* Makes the actual HTTP request with timeout handling
|
|
79
|
+
*/
|
|
80
|
+
private makeRequest;
|
|
81
|
+
/**
|
|
82
|
+
* Processes the fetch response and converts to APIResponse format
|
|
83
|
+
*/
|
|
84
|
+
private processResponse;
|
|
85
|
+
/**
|
|
86
|
+
* Creates appropriate error based on response status and data
|
|
87
|
+
*/
|
|
88
|
+
private createErrorFromResponse;
|
|
89
|
+
/**
|
|
90
|
+
* Extracts error message from response data
|
|
91
|
+
*/
|
|
92
|
+
private extractErrorMessage;
|
|
93
|
+
/**
|
|
94
|
+
* Extracts validation details from error response
|
|
95
|
+
*/
|
|
96
|
+
private extractValidationDetails;
|
|
97
|
+
/**
|
|
98
|
+
* Extracts rate limit information from response headers
|
|
99
|
+
*/
|
|
100
|
+
private extractRateLimitInfo;
|
|
101
|
+
/**
|
|
102
|
+
* Builds the complete URL for the request
|
|
103
|
+
*/
|
|
104
|
+
private buildUrl;
|
|
105
|
+
/**
|
|
106
|
+
* Builds RequestInit options for the fetch request
|
|
107
|
+
*/
|
|
108
|
+
private buildRequestOptions;
|
|
109
|
+
/**
|
|
110
|
+
* Determines if an error should prevent retrying
|
|
111
|
+
*/
|
|
112
|
+
private shouldNotRetry;
|
|
113
|
+
/**
|
|
114
|
+
* Calculates retry delay with exponential backoff
|
|
115
|
+
*/
|
|
116
|
+
private calculateRetryDelay;
|
|
117
|
+
/**
|
|
118
|
+
* Utility method to create delay
|
|
119
|
+
*/
|
|
120
|
+
private delay;
|
|
121
|
+
/**
|
|
122
|
+
* Gets the interceptor manager for advanced request/response handling
|
|
123
|
+
*
|
|
124
|
+
* @returns InterceptorManager instance
|
|
125
|
+
*/
|
|
126
|
+
getInterceptors(): InterceptorManager;
|
|
127
|
+
/**
|
|
128
|
+
* Adds a request interceptor
|
|
129
|
+
*
|
|
130
|
+
* @param interceptor - Request interceptor function
|
|
131
|
+
* @returns Interceptor ID for removal
|
|
132
|
+
*/
|
|
133
|
+
addRequestInterceptor(interceptor: Parameters<InterceptorManager["addRequestInterceptor"]>[0]): number;
|
|
134
|
+
/**
|
|
135
|
+
* Adds a response interceptor
|
|
136
|
+
*
|
|
137
|
+
* @param interceptor - Response interceptor function
|
|
138
|
+
* @returns Interceptor ID for removal
|
|
139
|
+
*/
|
|
140
|
+
addResponseInterceptor(interceptor: Parameters<InterceptorManager["addResponseInterceptor"]>[0]): number;
|
|
141
|
+
/**
|
|
142
|
+
* Adds an error interceptor
|
|
143
|
+
*
|
|
144
|
+
* @param interceptor - Error interceptor function
|
|
145
|
+
* @returns Interceptor ID for removal
|
|
146
|
+
*/
|
|
147
|
+
addErrorInterceptor(interceptor: Parameters<InterceptorManager["addErrorInterceptor"]>[0]): number;
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=HttpClient.d.ts.map
|
|
@@ -0,0 +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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IAQ1B;;;;;;;;OAQG;YACW,OAAO;IAgErB;;OAEG;YACW,WAAW;IA0CzB;;OAEG;YACW,eAAe;IAuC7B;;OAEG;IACH,OAAO,CAAC,uBAAuB;IA6D/B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAa3B;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAUhC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAgB5B;;OAEG;IACH,OAAO,CAAC,QAAQ;IA8BhB;;OAEG;YACW,mBAAmB;IAuCjC;;OAEG;IACH,OAAO,CAAC,cAAc;IAStB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAS3B;;OAEG;IACH,OAAO,CAAC,KAAK;IAMb;;;;OAIG;IACH,eAAe,IAAI,kBAAkB;IAIrC;;;;;OAKG;IACH,qBAAqB,CACnB,WAAW,EAAE,UAAU,CAAC,kBAAkB,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC,GACtE,MAAM;IAIT;;;;;OAKG;IACH,sBAAsB,CACpB,WAAW,EAAE,UAAU,CAAC,kBAAkB,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC,GACvE,MAAM;IAIT;;;;;OAKG;IACH,mBAAmB,CACjB,WAAW,EAAE,UAAU,CAAC,kBAAkB,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC,GACpE,MAAM;CAGV"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { APIResponse } from "../types";
|
|
2
|
+
export type RequestInterceptor = (url: string, options: RequestInit) => Promise<{
|
|
3
|
+
url: string;
|
|
4
|
+
options: RequestInit;
|
|
5
|
+
}> | {
|
|
6
|
+
url: string;
|
|
7
|
+
options: RequestInit;
|
|
8
|
+
};
|
|
9
|
+
export type ResponseInterceptor = (response: APIResponse<any>, request: {
|
|
10
|
+
url: string;
|
|
11
|
+
options: RequestInit;
|
|
12
|
+
}) => Promise<APIResponse<any>> | APIResponse<any>;
|
|
13
|
+
export type ErrorInterceptor = (error: Error, request: {
|
|
14
|
+
url: string;
|
|
15
|
+
options: RequestInit;
|
|
16
|
+
}) => Promise<never | APIResponse<any>> | never | APIResponse<any>;
|
|
17
|
+
export declare class InterceptorManager {
|
|
18
|
+
private requestInterceptors;
|
|
19
|
+
private responseInterceptors;
|
|
20
|
+
private errorInterceptors;
|
|
21
|
+
addRequestInterceptor(interceptor: RequestInterceptor): number;
|
|
22
|
+
removeRequestInterceptor(id: number): void;
|
|
23
|
+
executeRequestInterceptors(url: string, options: RequestInit): Promise<{
|
|
24
|
+
url: string;
|
|
25
|
+
options: RequestInit;
|
|
26
|
+
}>;
|
|
27
|
+
addResponseInterceptor(interceptor: ResponseInterceptor): number;
|
|
28
|
+
removeResponseInterceptor(id: number): void;
|
|
29
|
+
executeResponseInterceptors<T>(response: APIResponse<T>, request: {
|
|
30
|
+
url: string;
|
|
31
|
+
options: RequestInit;
|
|
32
|
+
}): Promise<APIResponse<T>>;
|
|
33
|
+
addErrorInterceptor(interceptor: ErrorInterceptor): number;
|
|
34
|
+
removeErrorInterceptor(id: number): void;
|
|
35
|
+
executeErrorInterceptors(error: Error, request: {
|
|
36
|
+
url: string;
|
|
37
|
+
options: RequestInit;
|
|
38
|
+
}): Promise<never | APIResponse<any>>;
|
|
39
|
+
clear(): void;
|
|
40
|
+
}
|
|
41
|
+
export declare const createLoggingInterceptor: (debug?: boolean) => {
|
|
42
|
+
request: RequestInterceptor;
|
|
43
|
+
response: ResponseInterceptor;
|
|
44
|
+
error: ErrorInterceptor;
|
|
45
|
+
};
|
|
46
|
+
export declare const createTimingInterceptor: () => {
|
|
47
|
+
request: RequestInterceptor;
|
|
48
|
+
response: ResponseInterceptor;
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=interceptors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptors.d.ts","sourceRoot":"","sources":["../../src/http/interceptors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,M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