@xbg.solutions/bpsk-utils-api-client 1.2.3
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/lib/index.d.ts +10 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +14 -0
- package/lib/index.js.map +1 -0
- package/lib/services/api/api.service.d.ts +67 -0
- package/lib/services/api/api.service.d.ts.map +1 -0
- package/lib/services/api/api.service.js +344 -0
- package/lib/services/api/api.service.js.map +1 -0
- package/lib/services/api/index.d.ts +13 -0
- package/lib/services/api/index.d.ts.map +1 -0
- package/lib/services/api/index.js +15 -0
- package/lib/services/api/index.js.map +1 -0
- package/lib/services/api/request-handler.d.ts +17 -0
- package/lib/services/api/request-handler.d.ts.map +1 -0
- package/lib/services/api/request-handler.js +289 -0
- package/lib/services/api/request-handler.js.map +1 -0
- package/lib/services/api/response-handler.d.ts +16 -0
- package/lib/services/api/response-handler.d.ts.map +1 -0
- package/lib/services/api/response-handler.js +254 -0
- package/lib/services/api/response-handler.js.map +1 -0
- package/lib/services/caching/api-cache.service.d.ts +97 -0
- package/lib/services/caching/api-cache.service.d.ts.map +1 -0
- package/lib/services/caching/api-cache.service.js +294 -0
- package/lib/services/caching/api-cache.service.js.map +1 -0
- package/lib/services/caching/cache.service.d.ts +86 -0
- package/lib/services/caching/cache.service.d.ts.map +1 -0
- package/lib/services/caching/cache.service.js +519 -0
- package/lib/services/caching/cache.service.js.map +1 -0
- package/lib/services/caching/index.d.ts +5 -0
- package/lib/services/caching/index.d.ts.map +1 -0
- package/lib/services/caching/index.js +3 -0
- package/lib/services/caching/index.js.map +1 -0
- package/lib/stores/api.service.d.ts +6 -0
- package/lib/stores/api.service.d.ts.map +1 -0
- package/lib/stores/api.service.js +6 -0
- package/lib/stores/api.service.js.map +1 -0
- package/lib/stores/request-handler.d.ts +6 -0
- package/lib/stores/request-handler.d.ts.map +1 -0
- package/lib/stores/request-handler.js +6 -0
- package/lib/stores/request-handler.js.map +1 -0
- package/lib/stores/response-handler.d.ts +6 -0
- package/lib/stores/response-handler.d.ts.map +1 -0
- package/lib/stores/response-handler.js +6 -0
- package/lib/stores/response-handler.js.map +1 -0
- package/lib/utils/cache-helpers.d.ts +112 -0
- package/lib/utils/cache-helpers.d.ts.map +1 -0
- package/lib/utils/cache-helpers.js +302 -0
- package/lib/utils/cache-helpers.js.map +1 -0
- package/package.json +27 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './services/api/api.service';
|
|
2
|
+
export * from './services/api/request-handler';
|
|
3
|
+
export * from './services/api/response-handler';
|
|
4
|
+
export * from './services/caching/api-cache.service';
|
|
5
|
+
export * from './services/caching/cache.service';
|
|
6
|
+
export * from './stores/api.service';
|
|
7
|
+
export * from './stores/request-handler';
|
|
8
|
+
export * from './stores/response-handler';
|
|
9
|
+
export * from './utils/cache-helpers';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iCAAiC,CAAC;AAChD,cAAc,sCAAsC,CAAC;AACrD,cAAc,kCAAkC,CAAC;AAGjD,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAG1C,cAAc,uBAAuB,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// API client package barrel exports
|
|
2
|
+
// Services
|
|
3
|
+
export * from './services/api/api.service';
|
|
4
|
+
export * from './services/api/request-handler';
|
|
5
|
+
export * from './services/api/response-handler';
|
|
6
|
+
export * from './services/caching/api-cache.service';
|
|
7
|
+
export * from './services/caching/cache.service';
|
|
8
|
+
// Stores
|
|
9
|
+
export * from './stores/api.service';
|
|
10
|
+
export * from './stores/request-handler';
|
|
11
|
+
export * from './stores/response-handler';
|
|
12
|
+
// Utils
|
|
13
|
+
export * from './utils/cache-helpers';
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAEpC,WAAW;AACX,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iCAAiC,CAAC;AAChD,cAAc,sCAAsC,CAAC;AACrD,cAAc,kCAAkC,CAAC;AAEjD,SAAS;AACT,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAE1C,QAAQ;AACR,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/lib/services/api/api.service.ts
|
|
3
|
+
* API Service
|
|
4
|
+
*
|
|
5
|
+
* A centralized service for API communication with support for:
|
|
6
|
+
* - Type-safe request methods (GET, POST, PUT, DELETE)
|
|
7
|
+
* - Authentication and CSRF protection
|
|
8
|
+
* - Error handling and retry logic
|
|
9
|
+
* - Event publishing
|
|
10
|
+
* - Request deduplication
|
|
11
|
+
*/
|
|
12
|
+
import type { IApiService } from '@xbg.solutions/bpsk-core';
|
|
13
|
+
import type { RequestOptions, SafeRequestResult } from '@xbg.solutions/bpsk-core';
|
|
14
|
+
/**
|
|
15
|
+
* API Service Implementation
|
|
16
|
+
*/
|
|
17
|
+
declare class ApiService implements IApiService {
|
|
18
|
+
private inFlightRequests;
|
|
19
|
+
constructor();
|
|
20
|
+
/**
|
|
21
|
+
* Performs a GET request
|
|
22
|
+
*/
|
|
23
|
+
get<T>(url: string, options?: RequestOptions): Promise<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Performs a POST request
|
|
26
|
+
*/
|
|
27
|
+
post<T>(url: string, data?: any, options?: RequestOptions): Promise<T>;
|
|
28
|
+
/**
|
|
29
|
+
* Performs a PUT request
|
|
30
|
+
*/
|
|
31
|
+
put<T>(url: string, data?: any, options?: RequestOptions): Promise<T>;
|
|
32
|
+
/**
|
|
33
|
+
* Performs a DELETE request
|
|
34
|
+
*/
|
|
35
|
+
delete<T>(url: string, options?: RequestOptions): Promise<T>;
|
|
36
|
+
/**
|
|
37
|
+
* Performs a PATCH request
|
|
38
|
+
*/
|
|
39
|
+
patch<T>(url: string, data?: any, options?: RequestOptions): Promise<T>;
|
|
40
|
+
/**
|
|
41
|
+
* Core request method that handles all API communication
|
|
42
|
+
*/
|
|
43
|
+
private request;
|
|
44
|
+
/**
|
|
45
|
+
* Safe version of GET that never throws
|
|
46
|
+
*/
|
|
47
|
+
safeGet<T>(url: string, options?: RequestOptions): Promise<SafeRequestResult<T>>;
|
|
48
|
+
/**
|
|
49
|
+
* Safe version of POST that never throws
|
|
50
|
+
*/
|
|
51
|
+
safePost<T>(url: string, data?: any, options?: RequestOptions): Promise<SafeRequestResult<T>>;
|
|
52
|
+
/**
|
|
53
|
+
* Safe version of PUT that never throws
|
|
54
|
+
*/
|
|
55
|
+
safePut<T>(url: string, data?: any, options?: RequestOptions): Promise<SafeRequestResult<T>>;
|
|
56
|
+
/**
|
|
57
|
+
* Safe version of DELETE that never throws
|
|
58
|
+
*/
|
|
59
|
+
safeDelete<T>(url: string, options?: RequestOptions): Promise<SafeRequestResult<T>>;
|
|
60
|
+
/**
|
|
61
|
+
* Safe version of PATCH that never throws
|
|
62
|
+
*/
|
|
63
|
+
safePatch<T>(url: string, data?: any, options?: RequestOptions): Promise<SafeRequestResult<T>>;
|
|
64
|
+
}
|
|
65
|
+
export declare const apiService: ApiService;
|
|
66
|
+
export {};
|
|
67
|
+
//# sourceMappingURL=api.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.service.d.ts","sourceRoot":"","sources":["../../../src/services/api/api.service.ts"],"names":[],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C;IAoBhC;;OAEG;IACG,OAAO,CAAC,CAAC,EACb,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,GAAG,EACV,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAoBhC;;OAEG;IACG,UAAU,CAAC,CAAC,EAChB,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAoBhC;;OAEG;IACG,SAAS,CAAC,CAAC,EACf,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,GAAG,EACV,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;CAmBjC;AAGD,eAAO,MAAM,UAAU,YAAmB,CAAC"}
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/lib/services/api/api.service.ts
|
|
3
|
+
* API Service
|
|
4
|
+
*
|
|
5
|
+
* A centralized service for API communication with support for:
|
|
6
|
+
* - Type-safe request methods (GET, POST, PUT, DELETE)
|
|
7
|
+
* - Authentication and CSRF protection
|
|
8
|
+
* - Error handling and retry logic
|
|
9
|
+
* - Event publishing
|
|
10
|
+
* - Request deduplication
|
|
11
|
+
*/
|
|
12
|
+
import { loggerService } from '@xbg.solutions/bpsk-core';
|
|
13
|
+
import { publish } from '@xbg.solutions/bpsk-core';
|
|
14
|
+
import { ApiError, AuthError, NetworkError, normalizeError } from '@xbg.solutions/bpsk-core';
|
|
15
|
+
import { API_CONSTANTS } from '@xbg.solutions/bpsk-core';
|
|
16
|
+
import { requestHandler } from './request-handler';
|
|
17
|
+
import { responseHandler } from './response-handler';
|
|
18
|
+
// Create a context-aware logger
|
|
19
|
+
const apiLogger = loggerService.withContext('ApiService');
|
|
20
|
+
/**
|
|
21
|
+
* API Service Implementation
|
|
22
|
+
*/
|
|
23
|
+
class ApiService {
|
|
24
|
+
constructor() {
|
|
25
|
+
this.inFlightRequests = new Map();
|
|
26
|
+
apiLogger.info('API Service initialized');
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Performs a GET request
|
|
30
|
+
*/
|
|
31
|
+
async get(url, options = {}) {
|
|
32
|
+
// Extract params for URL building
|
|
33
|
+
const params = options.params || {};
|
|
34
|
+
// Note: We're not removing params here anymore since we do it in request()
|
|
35
|
+
// But we're keeping a copy of options for deduplication and other uses
|
|
36
|
+
const requestOptions = { ...options };
|
|
37
|
+
const fullUrl = requestHandler.buildUrl(url, params);
|
|
38
|
+
// Check if this is a cacheable request
|
|
39
|
+
const shouldDedup = requestOptions.skipDeduplication !== true;
|
|
40
|
+
const requestKey = shouldDedup ? `GET:${fullUrl}` : null;
|
|
41
|
+
// Return existing request if one is in flight
|
|
42
|
+
if (requestKey && this.inFlightRequests.has(requestKey)) {
|
|
43
|
+
apiLogger.info(`Reusing in-flight request for ${fullUrl}`, {
|
|
44
|
+
url: fullUrl,
|
|
45
|
+
requestKey
|
|
46
|
+
});
|
|
47
|
+
return this.inFlightRequests.get(requestKey);
|
|
48
|
+
}
|
|
49
|
+
// Create the request promise
|
|
50
|
+
const requestPromise = this.request('GET', fullUrl, null, requestOptions);
|
|
51
|
+
// Store for deduplication if applicable
|
|
52
|
+
if (requestKey) {
|
|
53
|
+
this.inFlightRequests.set(requestKey, requestPromise);
|
|
54
|
+
// Clean up map entry when request completes
|
|
55
|
+
requestPromise.finally(() => {
|
|
56
|
+
this.inFlightRequests.delete(requestKey);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return requestPromise;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Performs a POST request
|
|
63
|
+
*/
|
|
64
|
+
async post(url, data, options = {}) {
|
|
65
|
+
return this.request('POST', url, data, options);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Performs a PUT request
|
|
69
|
+
*/
|
|
70
|
+
async put(url, data, options = {}) {
|
|
71
|
+
return this.request('PUT', url, data, options);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Performs a DELETE request
|
|
75
|
+
*/
|
|
76
|
+
async delete(url, options = {}) {
|
|
77
|
+
return this.request('DELETE', url, null, options);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Performs a PATCH request
|
|
81
|
+
*/
|
|
82
|
+
async patch(url, data, options = {}) {
|
|
83
|
+
return this.request('PATCH', url, data, options);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Core request method that handles all API communication
|
|
87
|
+
*/
|
|
88
|
+
async request(method, url, data, options = {}) {
|
|
89
|
+
const timeout = options.timeout || API_CONSTANTS.REQUEST_CONFIG.timeout;
|
|
90
|
+
const maxRetries = options.retryCount !== undefined
|
|
91
|
+
? options.retryCount
|
|
92
|
+
: API_CONSTANTS.REQUEST_CONFIG.retryCount;
|
|
93
|
+
let retryCount = 0;
|
|
94
|
+
let lastError = null;
|
|
95
|
+
const logContext = {
|
|
96
|
+
method,
|
|
97
|
+
url,
|
|
98
|
+
timeout,
|
|
99
|
+
maxRetries
|
|
100
|
+
};
|
|
101
|
+
// Emit request start event
|
|
102
|
+
publish(API_CONSTANTS.EVENTS.REQUEST_START, {
|
|
103
|
+
method,
|
|
104
|
+
url,
|
|
105
|
+
timestamp: Date.now()
|
|
106
|
+
}, 'ApiService');
|
|
107
|
+
// Track start time for logging
|
|
108
|
+
const startTime = performance.now();
|
|
109
|
+
while (retryCount <= maxRetries) {
|
|
110
|
+
try {
|
|
111
|
+
// Create a clean copy of options without the params property
|
|
112
|
+
const cleanOptions = { ...options };
|
|
113
|
+
delete cleanOptions.params;
|
|
114
|
+
// Prepare the request with clean options
|
|
115
|
+
const requestOptions = await requestHandler.prepareRequest(method, url, data, cleanOptions);
|
|
116
|
+
// Execute the request
|
|
117
|
+
const response = await requestHandler.executeRequest(url, requestOptions, timeout);
|
|
118
|
+
// Process the response
|
|
119
|
+
const result = await responseHandler.processResponse(response, method, url);
|
|
120
|
+
// Calculate request duration
|
|
121
|
+
const duration = performance.now() - startTime;
|
|
122
|
+
// Emit success event
|
|
123
|
+
publish(API_CONSTANTS.EVENTS.REQUEST_SUCCESS, {
|
|
124
|
+
method,
|
|
125
|
+
url,
|
|
126
|
+
status: response.status,
|
|
127
|
+
duration,
|
|
128
|
+
timestamp: Date.now()
|
|
129
|
+
}, 'ApiService');
|
|
130
|
+
// Log success
|
|
131
|
+
apiLogger.info(`${method} ${url} completed successfully`, {
|
|
132
|
+
...logContext,
|
|
133
|
+
status: response.status,
|
|
134
|
+
duration: Math.round(duration)
|
|
135
|
+
});
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
// Ensure lastError is always an Error object
|
|
140
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
141
|
+
// Special case: if this error indicates a successful token refresh,
|
|
142
|
+
// we should retry the request with the new token
|
|
143
|
+
if (error instanceof AuthError &&
|
|
144
|
+
error.context &&
|
|
145
|
+
error.context.tokenRefreshed) {
|
|
146
|
+
apiLogger.info(`Retrying ${method} ${url} after token refresh`, logContext);
|
|
147
|
+
continue; // Retry immediately with refreshed token
|
|
148
|
+
}
|
|
149
|
+
// Check if we should retry the request
|
|
150
|
+
const shouldRetry =
|
|
151
|
+
// Not the last attempt
|
|
152
|
+
retryCount < maxRetries &&
|
|
153
|
+
// And either network error or server error that's marked retryable
|
|
154
|
+
((error instanceof NetworkError && !error.isOffline) ||
|
|
155
|
+
(error instanceof ApiError &&
|
|
156
|
+
error.statusCode &&
|
|
157
|
+
error.statusCode >= 500 &&
|
|
158
|
+
error.context &&
|
|
159
|
+
error.context.isRetryable));
|
|
160
|
+
if (shouldRetry) {
|
|
161
|
+
// Increment retry count
|
|
162
|
+
retryCount++;
|
|
163
|
+
// Calculate delay with exponential backoff and jitter
|
|
164
|
+
const delay = API_CONSTANTS.REQUEST_CONFIG.retryDelay *
|
|
165
|
+
Math.pow(2, retryCount - 1) *
|
|
166
|
+
(0.8 + Math.random() * 0.4);
|
|
167
|
+
apiLogger.warn(`Retrying ${method} ${url} (${retryCount}/${maxRetries}) after ${Math.round(delay)}ms`, {
|
|
168
|
+
...logContext,
|
|
169
|
+
retryCount,
|
|
170
|
+
delay: Math.round(delay),
|
|
171
|
+
error: lastError.message,
|
|
172
|
+
errorType: lastError.constructor.name,
|
|
173
|
+
statusCode: error instanceof ApiError ? error.statusCode : undefined
|
|
174
|
+
});
|
|
175
|
+
// Wait before retrying
|
|
176
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
// Calculate request duration
|
|
180
|
+
const duration = performance.now() - startTime;
|
|
181
|
+
// Emit error event with appropriate type
|
|
182
|
+
if (error instanceof AuthError) {
|
|
183
|
+
publish(API_CONSTANTS.EVENTS.AUTH_ERROR, {
|
|
184
|
+
method,
|
|
185
|
+
url,
|
|
186
|
+
error: lastError.message,
|
|
187
|
+
status: error.statusCode,
|
|
188
|
+
duration,
|
|
189
|
+
timestamp: Date.now()
|
|
190
|
+
}, 'ApiService');
|
|
191
|
+
}
|
|
192
|
+
else if (error instanceof NetworkError) {
|
|
193
|
+
publish(API_CONSTANTS.EVENTS.NETWORK_ERROR, {
|
|
194
|
+
method,
|
|
195
|
+
url,
|
|
196
|
+
error: lastError.message,
|
|
197
|
+
isOffline: error.isOffline,
|
|
198
|
+
isTimeout: error.isTimeout,
|
|
199
|
+
duration,
|
|
200
|
+
timestamp: Date.now()
|
|
201
|
+
}, 'ApiService');
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
publish(API_CONSTANTS.EVENTS.REQUEST_ERROR, {
|
|
205
|
+
method,
|
|
206
|
+
url,
|
|
207
|
+
error: lastError.message,
|
|
208
|
+
status: error instanceof ApiError ? error.statusCode : undefined,
|
|
209
|
+
duration,
|
|
210
|
+
timestamp: Date.now()
|
|
211
|
+
}, 'ApiService');
|
|
212
|
+
}
|
|
213
|
+
// Log error - ensure it's an Error object
|
|
214
|
+
apiLogger.error(`${method} ${url} failed`, lastError, {
|
|
215
|
+
...logContext,
|
|
216
|
+
duration: Math.round(duration),
|
|
217
|
+
retryAttempts: retryCount
|
|
218
|
+
});
|
|
219
|
+
// Rethrow the error
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
// If we got here, we exhausted all retries
|
|
224
|
+
// Ensure lastError is not null
|
|
225
|
+
if (!lastError) {
|
|
226
|
+
lastError = new Error(`Request to ${url} failed after ${retryCount} retries`);
|
|
227
|
+
}
|
|
228
|
+
apiLogger.error(`${method} ${url} failed after ${retryCount} retries`, lastError, logContext);
|
|
229
|
+
throw lastError;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Safe version of GET that never throws
|
|
233
|
+
*/
|
|
234
|
+
async safeGet(url, options) {
|
|
235
|
+
try {
|
|
236
|
+
const data = await this.get(url, options);
|
|
237
|
+
return { success: true, data };
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
apiLogger.info(`Safe GET request to ${url} caught error`, {
|
|
241
|
+
url,
|
|
242
|
+
error: error instanceof Error ? error.message : String(error)
|
|
243
|
+
});
|
|
244
|
+
// Ensure we return a properly normalized error
|
|
245
|
+
return {
|
|
246
|
+
success: false,
|
|
247
|
+
error: error instanceof Error ?
|
|
248
|
+
normalizeError(error) :
|
|
249
|
+
normalizeError(new Error(String(error)))
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Safe version of POST that never throws
|
|
255
|
+
*/
|
|
256
|
+
async safePost(url, data, options) {
|
|
257
|
+
try {
|
|
258
|
+
const result = await this.post(url, data, options);
|
|
259
|
+
return { success: true, data: result };
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
apiLogger.info(`Safe POST request to ${url} caught error`, {
|
|
263
|
+
url,
|
|
264
|
+
error: error instanceof Error ? error.message : String(error)
|
|
265
|
+
});
|
|
266
|
+
// Ensure we return a properly normalized error
|
|
267
|
+
return {
|
|
268
|
+
success: false,
|
|
269
|
+
error: error instanceof Error ?
|
|
270
|
+
normalizeError(error) :
|
|
271
|
+
normalizeError(new Error(String(error)))
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Safe version of PUT that never throws
|
|
277
|
+
*/
|
|
278
|
+
async safePut(url, data, options) {
|
|
279
|
+
try {
|
|
280
|
+
const result = await this.put(url, data, options);
|
|
281
|
+
return { success: true, data: result };
|
|
282
|
+
}
|
|
283
|
+
catch (error) {
|
|
284
|
+
apiLogger.info(`Safe PUT request to ${url} caught error`, {
|
|
285
|
+
url,
|
|
286
|
+
error: error instanceof Error ? error.message : String(error)
|
|
287
|
+
});
|
|
288
|
+
// Ensure we return a properly normalized error
|
|
289
|
+
return {
|
|
290
|
+
success: false,
|
|
291
|
+
error: error instanceof Error ?
|
|
292
|
+
normalizeError(error) :
|
|
293
|
+
normalizeError(new Error(String(error)))
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Safe version of DELETE that never throws
|
|
299
|
+
*/
|
|
300
|
+
async safeDelete(url, options) {
|
|
301
|
+
try {
|
|
302
|
+
const result = await this.delete(url, options);
|
|
303
|
+
return { success: true, data: result };
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
apiLogger.info(`Safe DELETE request to ${url} caught error`, {
|
|
307
|
+
url,
|
|
308
|
+
error: error instanceof Error ? error.message : String(error)
|
|
309
|
+
});
|
|
310
|
+
// Ensure we return a properly normalized error
|
|
311
|
+
return {
|
|
312
|
+
success: false,
|
|
313
|
+
error: error instanceof Error ?
|
|
314
|
+
normalizeError(error) :
|
|
315
|
+
normalizeError(new Error(String(error)))
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Safe version of PATCH that never throws
|
|
321
|
+
*/
|
|
322
|
+
async safePatch(url, data, options) {
|
|
323
|
+
try {
|
|
324
|
+
const result = await this.patch(url, data, options);
|
|
325
|
+
return { success: true, data: result };
|
|
326
|
+
}
|
|
327
|
+
catch (error) {
|
|
328
|
+
apiLogger.info(`Safe PATCH request to ${url} caught error`, {
|
|
329
|
+
url,
|
|
330
|
+
error: error instanceof Error ? error.message : String(error)
|
|
331
|
+
});
|
|
332
|
+
// Ensure we return a properly normalized error
|
|
333
|
+
return {
|
|
334
|
+
success: false,
|
|
335
|
+
error: error instanceof Error ?
|
|
336
|
+
normalizeError(error) :
|
|
337
|
+
normalizeError(new Error(String(error)))
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
// Create and export a singleton instance
|
|
343
|
+
export const apiService = new ApiService();
|
|
344
|
+
//# sourceMappingURL=api.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.service.js","sourceRoot":"","sources":["../../../src/services/api/api.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EACL,QAAQ,EACR,SAAS,EACT,YAAY,EAEZ,cAAc,EAEf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAKrD,gCAAgC;AAChC,MAAM,SAAS,GAAG,aAAa,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;AAE1D;;GAEG;AACH,MAAM,UAAU;IAGd;QACE,IAAI,CAAC,gBAAgB,GAAG,IAAI,GAAG,EAAE,CAAC;QAClC,SAAS,CA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oBAC7B,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;oBACvB,cAAc,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;aAC3C,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,SAAS,CACb,GAAW,EACX,IAAU,EACV,OAAwB;QAExB,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAI,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;YACvD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QACzC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,SAAS,CAAC,IAAI,CAAC,yBAAyB,GAAG,eAAe,EAAE;gBAC1D,GAAG;gBACH,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAC9D,CAAC,CAAC;YAEH,+CAA+C;YAC/C,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC;oBAC7B,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;oBACvB,cAAc,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;aAC3C,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAED,yCAAyC;AACzC,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/lib/services/api/index.ts
|
|
3
|
+
* API Service exports
|
|
4
|
+
*
|
|
5
|
+
* Centralizes all API-related exports to provide a clean interface
|
|
6
|
+
* for importing API functionality throughout the application.
|
|
7
|
+
*/
|
|
8
|
+
export { apiService } from './api.service';
|
|
9
|
+
export { requestHandler } from './request-handler';
|
|
10
|
+
export { responseHandler } from './response-handler';
|
|
11
|
+
export { API_CONSTANTS } from '@xbg.solutions/bpsk-core';
|
|
12
|
+
export type { RequestOptions, SafeRequestResult, ApiResponse, PaginationParams, ResponseMetadata, ApiClient } from '@xbg.solutions/bpsk-core';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAGzD,YAAY,EACV,cAAc,EACd,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACV,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/lib/services/api/index.ts
|
|
3
|
+
* API Service exports
|
|
4
|
+
*
|
|
5
|
+
* Centralizes all API-related exports to provide a clean interface
|
|
6
|
+
* for importing API functionality throughout the application.
|
|
7
|
+
*/
|
|
8
|
+
// Export the main API service
|
|
9
|
+
export { apiService } from './api.service';
|
|
10
|
+
// Export request and response handlers for advanced usage scenarios
|
|
11
|
+
export { requestHandler } from './request-handler';
|
|
12
|
+
export { responseHandler } from './response-handler';
|
|
13
|
+
// Re-export API constants for consumers who need them
|
|
14
|
+
export { API_CONSTANTS } from '@xbg.solutions/bpsk-core';
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,8BAA8B;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,oEAAoE;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,sDAAsD;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/lib/services/api/request-handler.ts
|
|
3
|
+
* API Request Handler
|
|
4
|
+
*
|
|
5
|
+
* Handles API request preparation with support for:
|
|
6
|
+
* - Authentication token inclusion
|
|
7
|
+
* - CSRF protection
|
|
8
|
+
* - Request timeout management
|
|
9
|
+
* - Header normalization
|
|
10
|
+
* - Data serialization
|
|
11
|
+
*/
|
|
12
|
+
import type { IRequestHandler } from '@xbg.solutions/bpsk-core';
|
|
13
|
+
/**
|
|
14
|
+
* Request Handler implementation
|
|
15
|
+
*/
|
|
16
|
+
export declare const requestHandler: IRequestHandler;
|
|
17
|
+
//# sourceMappingURL=request-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-handler.d.ts","sourceRoot":"","sources":["../../../src/services/api/request-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAYH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAmChE;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,eA2S5B,CAAC"}
|