@aifabrix/miso-client 3.8.2 → 3.9.0
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 +45 -0
- package/dist/index.d.ts +30 -157
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -163
- package/dist/index.js.map +1 -1
- package/dist/services/auth-error-handler.d.ts +21 -0
- package/dist/services/auth-error-handler.d.ts.map +1 -0
- package/dist/services/auth-error-handler.js +68 -0
- package/dist/services/auth-error-handler.js.map +1 -0
- package/dist/services/auth.service.d.ts +0 -1
- package/dist/services/auth.service.d.ts.map +1 -1
- package/dist/services/auth.service.js +31 -298
- package/dist/services/auth.service.js.map +1 -1
- package/dist/services/logger/logger.service.d.ts +8 -80
- package/dist/services/logger/logger.service.d.ts.map +1 -1
- package/dist/services/logger/logger.service.js +8 -80
- package/dist/services/logger/logger.service.js.map +1 -1
- package/dist/types/filter-schema.types.d.ts +104 -0
- package/dist/types/filter-schema.types.d.ts.map +1 -0
- package/dist/types/filter-schema.types.js +40 -0
- package/dist/types/filter-schema.types.js.map +1 -0
- package/dist/types/filter.types.d.ts +1 -1
- package/dist/types/filter.types.d.ts.map +1 -1
- package/dist/types/filter.types.js.map +1 -1
- package/dist/utils/data-client-auth.d.ts +5 -37
- package/dist/utils/data-client-auth.d.ts.map +1 -1
- package/dist/utils/data-client-auth.js +98 -377
- package/dist/utils/data-client-auth.js.map +1 -1
- package/dist/utils/data-client-init.d.ts +46 -0
- package/dist/utils/data-client-init.d.ts.map +1 -0
- package/dist/utils/data-client-init.js +128 -0
- package/dist/utils/data-client-init.js.map +1 -0
- package/dist/utils/data-client-oauth.d.ts +20 -0
- package/dist/utils/data-client-oauth.d.ts.map +1 -0
- package/dist/utils/data-client-oauth.js +138 -0
- package/dist/utils/data-client-oauth.js.map +1 -0
- package/dist/utils/data-client-permissions.d.ts +63 -0
- package/dist/utils/data-client-permissions.d.ts.map +1 -0
- package/dist/utils/data-client-permissions.js +123 -0
- package/dist/utils/data-client-permissions.js.map +1 -0
- package/dist/utils/data-client-request.d.ts +1 -1
- package/dist/utils/data-client-request.d.ts.map +1 -1
- package/dist/utils/data-client-request.js +27 -235
- package/dist/utils/data-client-request.js.map +1 -1
- package/dist/utils/data-client-response.d.ts +40 -0
- package/dist/utils/data-client-response.d.ts.map +1 -0
- package/dist/utils/data-client-response.js +144 -0
- package/dist/utils/data-client-response.js.map +1 -0
- package/dist/utils/data-client-roles.d.ts +63 -0
- package/dist/utils/data-client-roles.d.ts.map +1 -0
- package/dist/utils/data-client-roles.js +123 -0
- package/dist/utils/data-client-roles.js.map +1 -0
- package/dist/utils/data-client.d.ts +0 -185
- package/dist/utils/data-client.d.ts.map +1 -1
- package/dist/utils/data-client.js +66 -505
- package/dist/utils/data-client.js.map +1 -1
- package/dist/utils/filter-colon.utils.d.ts +26 -0
- package/dist/utils/filter-colon.utils.d.ts.map +1 -0
- package/dist/utils/filter-colon.utils.js +112 -0
- package/dist/utils/filter-colon.utils.js.map +1 -0
- package/dist/utils/filter-schema.utils.d.ts +84 -0
- package/dist/utils/filter-schema.utils.d.ts.map +1 -0
- package/dist/utils/filter-schema.utils.js +381 -0
- package/dist/utils/filter-schema.utils.js.map +1 -0
- package/dist/utils/filter.utils.d.ts +9 -85
- package/dist/utils/filter.utils.d.ts.map +1 -1
- package/dist/utils/filter.utils.js +79 -138
- package/dist/utils/filter.utils.js.map +1 -1
- package/dist/utils/http-error-handler.d.ts +22 -0
- package/dist/utils/http-error-handler.d.ts.map +1 -0
- package/dist/utils/http-error-handler.js +84 -0
- package/dist/utils/http-error-handler.js.map +1 -0
- package/dist/utils/http-response-validator.d.ts +15 -0
- package/dist/utils/http-response-validator.d.ts.map +1 -0
- package/dist/utils/http-response-validator.js +42 -0
- package/dist/utils/http-response-validator.js.map +1 -0
- package/dist/utils/internal-http-client.d.ts +4 -22
- package/dist/utils/internal-http-client.d.ts.map +1 -1
- package/dist/utils/internal-http-client.js +53 -337
- package/dist/utils/internal-http-client.js.map +1 -1
- package/dist/utils/token-utils.d.ts.map +1 -1
- package/dist/utils/token-utils.js +1 -29
- package/dist/utils/token-utils.js.map +1 -1
- package/package.json +1 -1
|
@@ -12,29 +12,7 @@ exports.filterQueryToJson = filterQueryToJson;
|
|
|
12
12
|
exports.jsonToFilterQuery = jsonToFilterQuery;
|
|
13
13
|
const filter_types_1 = require("../types/filter.types");
|
|
14
14
|
Object.defineProperty(exports, "FilterBuilder", { enumerable: true, get: function () { return filter_types_1.FilterBuilder; } });
|
|
15
|
-
|
|
16
|
-
* Normalize operator aliases to standard operator names.
|
|
17
|
-
* @param op - Operator name (may be alias)
|
|
18
|
-
* @returns Standard operator name
|
|
19
|
-
*/
|
|
20
|
-
function _normalizeOperator(op) {
|
|
21
|
-
const operatorMap = {
|
|
22
|
-
equals: "eq",
|
|
23
|
-
notEquals: "neq",
|
|
24
|
-
">": "gt",
|
|
25
|
-
"<": "lt",
|
|
26
|
-
">=": "gte",
|
|
27
|
-
"<=": "lte",
|
|
28
|
-
equal: "eq",
|
|
29
|
-
notEqual: "neq",
|
|
30
|
-
greaterThan: "gt",
|
|
31
|
-
lessThan: "lt",
|
|
32
|
-
greaterThanOrEqual: "gte",
|
|
33
|
-
lessThanOrEqual: "lte",
|
|
34
|
-
};
|
|
35
|
-
const normalized = operatorMap[op.toLowerCase()] || op;
|
|
36
|
-
return normalized;
|
|
37
|
-
}
|
|
15
|
+
const filter_colon_utils_1 = require("./filter-colon.utils");
|
|
38
16
|
/**
|
|
39
17
|
* Validate filter value for specific operators.
|
|
40
18
|
* @param op - Filter operator
|
|
@@ -70,7 +48,7 @@ function _parseJsonFilter(jsonFilter) {
|
|
|
70
48
|
}
|
|
71
49
|
const operators = fieldValue;
|
|
72
50
|
for (const [opStr, value] of Object.entries(operators)) {
|
|
73
|
-
const op =
|
|
51
|
+
const op = (0, filter_colon_utils_1.normalizeOperator)(opStr);
|
|
74
52
|
_validateFilterValue(op, value);
|
|
75
53
|
let normalizedValue;
|
|
76
54
|
if (op === "isNull" || op === "isNotNull") {
|
|
@@ -82,18 +60,17 @@ function _parseJsonFilter(jsonFilter) {
|
|
|
82
60
|
else {
|
|
83
61
|
normalizedValue = value;
|
|
84
62
|
}
|
|
85
|
-
result.push({
|
|
86
|
-
field,
|
|
87
|
-
op,
|
|
88
|
-
value: normalizedValue,
|
|
89
|
-
});
|
|
63
|
+
result.push({ field, op, value: normalizedValue });
|
|
90
64
|
}
|
|
91
65
|
}
|
|
92
66
|
return result;
|
|
93
67
|
}
|
|
94
68
|
/**
|
|
95
69
|
* Parse filter query parameters into structured FilterOption array.
|
|
96
|
-
* Supports JSON format
|
|
70
|
+
* Supports both JSON format and colon format.
|
|
71
|
+
*
|
|
72
|
+
* **JSON format**: object, JSON string, or URL-encoded JSON string
|
|
73
|
+
* **Colon format**: "field:operator:value" (e.g., "status:eq:active", "region:in:eu,us")
|
|
97
74
|
*
|
|
98
75
|
* @param query - Query parameters object (e.g., from URLSearchParams or request query)
|
|
99
76
|
* @returns Array of parsed filter options
|
|
@@ -101,23 +78,14 @@ function _parseJsonFilter(jsonFilter) {
|
|
|
101
78
|
*
|
|
102
79
|
* @example
|
|
103
80
|
* ```typescript
|
|
104
|
-
* //
|
|
81
|
+
* // JSON object format
|
|
105
82
|
* parseFilterParams({ filter: { status: { eq: 'active' } } });
|
|
106
83
|
*
|
|
107
|
-
* //
|
|
108
|
-
* parseFilterParams({ filter: '
|
|
109
|
-
*
|
|
110
|
-
* // URL-encoded JSON (from query string)
|
|
111
|
-
* parseFilterParams({ filter: '%7B%22status%22%3A%7B%22eq%22%3A%22active%22%7D%7D' });
|
|
84
|
+
* // Colon format (single filter)
|
|
85
|
+
* parseFilterParams({ filter: 'status:eq:active' });
|
|
112
86
|
*
|
|
113
|
-
* //
|
|
114
|
-
* parseFilterParams({
|
|
115
|
-
* filter: {
|
|
116
|
-
* status: { eq: 'active' },
|
|
117
|
-
* deletedAt: { isNull: null },
|
|
118
|
-
* region: { in: ['eu', 'us'] }
|
|
119
|
-
* }
|
|
120
|
-
* });
|
|
87
|
+
* // Colon format (multiple filters as array)
|
|
88
|
+
* parseFilterParams({ filter: ['status:eq:active', 'region:in:eu,us'] });
|
|
121
89
|
* ```
|
|
122
90
|
*/
|
|
123
91
|
function parseFilterParams(query) {
|
|
@@ -126,31 +94,80 @@ function parseFilterParams(query) {
|
|
|
126
94
|
return [];
|
|
127
95
|
}
|
|
128
96
|
try {
|
|
129
|
-
|
|
97
|
+
// Handle object filter (JSON format)
|
|
130
98
|
if (typeof filterParam === "object" && !Array.isArray(filterParam) && filterParam !== null) {
|
|
131
|
-
|
|
99
|
+
return _parseJsonFilter(filterParam);
|
|
132
100
|
}
|
|
133
|
-
|
|
101
|
+
// Handle string filter (could be JSON or colon format)
|
|
102
|
+
if (typeof filterParam === "string") {
|
|
103
|
+
if ((0, filter_colon_utils_1.isColonFormat)(filterParam)) {
|
|
104
|
+
return [(0, filter_colon_utils_1.parseColonFilter)(filterParam)];
|
|
105
|
+
}
|
|
106
|
+
// Try JSON format
|
|
134
107
|
try {
|
|
135
108
|
const decoded = decodeURIComponent(filterParam);
|
|
136
|
-
jsonFilter = JSON.parse(decoded);
|
|
109
|
+
const jsonFilter = JSON.parse(decoded);
|
|
110
|
+
if (Array.isArray(jsonFilter)) {
|
|
111
|
+
const result = [];
|
|
112
|
+
for (const item of jsonFilter) {
|
|
113
|
+
if (typeof item === "object" && item !== null) {
|
|
114
|
+
result.push(..._parseJsonFilter(item));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
return _parseJsonFilter(jsonFilter);
|
|
137
120
|
}
|
|
138
121
|
catch {
|
|
139
|
-
|
|
122
|
+
try {
|
|
123
|
+
const jsonFilter = JSON.parse(filterParam);
|
|
124
|
+
if (Array.isArray(jsonFilter)) {
|
|
125
|
+
const result = [];
|
|
126
|
+
for (const item of jsonFilter) {
|
|
127
|
+
if (typeof item === "object" && item !== null) {
|
|
128
|
+
result.push(..._parseJsonFilter(item));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
return _parseJsonFilter(jsonFilter);
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
if (filterParam.includes(":")) {
|
|
137
|
+
return [(0, filter_colon_utils_1.parseColonFilter)(filterParam)];
|
|
138
|
+
}
|
|
139
|
+
throw new Error(`Could not parse filter string: "${filterParam}"`);
|
|
140
|
+
}
|
|
140
141
|
}
|
|
141
142
|
}
|
|
142
|
-
|
|
143
|
+
// Handle array of filters (can be mixed JSON and colon format)
|
|
144
|
+
if (Array.isArray(filterParam)) {
|
|
143
145
|
const result = [];
|
|
144
146
|
for (const item of filterParam) {
|
|
145
147
|
if (typeof item === "string") {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const parsed = JSON.parse(decoded);
|
|
149
|
-
result.push(..._parseJsonFilter(parsed));
|
|
148
|
+
if ((0, filter_colon_utils_1.isColonFormat)(item)) {
|
|
149
|
+
result.push((0, filter_colon_utils_1.parseColonFilter)(item));
|
|
150
150
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
else {
|
|
152
|
+
try {
|
|
153
|
+
const decoded = decodeURIComponent(item);
|
|
154
|
+
const parsed = JSON.parse(decoded);
|
|
155
|
+
result.push(..._parseJsonFilter(parsed));
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
try {
|
|
159
|
+
const parsed = JSON.parse(item);
|
|
160
|
+
result.push(..._parseJsonFilter(parsed));
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
if (item.includes(":")) {
|
|
164
|
+
result.push((0, filter_colon_utils_1.parseColonFilter)(item));
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
throw new Error(`Could not parse filter item: "${item}"`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
154
171
|
}
|
|
155
172
|
}
|
|
156
173
|
else if (typeof item === "object" && item !== null) {
|
|
@@ -159,40 +176,19 @@ function parseFilterParams(query) {
|
|
|
159
176
|
}
|
|
160
177
|
return result;
|
|
161
178
|
}
|
|
162
|
-
|
|
163
|
-
throw new Error(`Invalid filter format. Expected object or string, got ${typeof filterParam}. Example: {"status": {"eq": "active"}}`);
|
|
164
|
-
}
|
|
165
|
-
if (typeof jsonFilter !== "object" || jsonFilter === null || Array.isArray(jsonFilter)) {
|
|
166
|
-
throw new Error(`Invalid filter format. Expected JSON object format: {"field": {"op": value}}. Got: ${typeof jsonFilter}`);
|
|
167
|
-
}
|
|
168
|
-
return _parseJsonFilter(jsonFilter);
|
|
179
|
+
throw new Error(`Invalid filter format. Expected object, string, or array, got ${typeof filterParam}.`);
|
|
169
180
|
}
|
|
170
181
|
catch (error) {
|
|
171
182
|
if (error instanceof Error) {
|
|
172
|
-
throw new Error(`Invalid filter format.
|
|
183
|
+
throw new Error(`Invalid filter format. ${error.message}`);
|
|
173
184
|
}
|
|
174
|
-
throw new Error(`Invalid filter format.
|
|
185
|
+
throw new Error(`Invalid filter format. Got: ${typeof filterParam}`);
|
|
175
186
|
}
|
|
176
187
|
}
|
|
177
188
|
/**
|
|
178
189
|
* Build query string from FilterQuery object using JSON format for filters.
|
|
179
|
-
*
|
|
180
190
|
* @param options - FilterQuery object with filters, sort, pagination, and field selection
|
|
181
191
|
* @returns Query string with URL-encoded JSON filter format
|
|
182
|
-
*
|
|
183
|
-
* @example
|
|
184
|
-
* ```typescript
|
|
185
|
-
* buildQueryString({
|
|
186
|
-
* filters: [
|
|
187
|
-
* { field: 'status', op: 'eq', value: 'active' },
|
|
188
|
-
* { field: 'age', op: 'gte', value: 18 }
|
|
189
|
-
* ],
|
|
190
|
-
* sort: ['-updated_at'],
|
|
191
|
-
* page: 1,
|
|
192
|
-
* pageSize: 25
|
|
193
|
-
* });
|
|
194
|
-
* // Returns: "filter=%7B%22status%22%3A%7B%22eq%22%3A%22active%22%7D%2C%22age%22%3A%7B%22gte%22%3A18%7D%7D&sort=-updated_at&page=1&page_size=25"
|
|
195
|
-
* ```
|
|
196
192
|
*/
|
|
197
193
|
function buildQueryString(options) {
|
|
198
194
|
const params = new URLSearchParams();
|
|
@@ -205,7 +201,6 @@ function buildQueryString(options) {
|
|
|
205
201
|
jsonFilter[filter.field][filter.op] = filter.value === null ? null : filter.value;
|
|
206
202
|
}
|
|
207
203
|
const jsonString = JSON.stringify(jsonFilter);
|
|
208
|
-
// URLSearchParams.append() automatically URL-encodes, so don't double-encode
|
|
209
204
|
params.append("filter", jsonString);
|
|
210
205
|
}
|
|
211
206
|
options.sort?.forEach((s) => params.append("sort", s));
|
|
@@ -223,23 +218,9 @@ function buildQueryString(options) {
|
|
|
223
218
|
/**
|
|
224
219
|
* Apply filters locally to an array (used for mocks/tests).
|
|
225
220
|
* Supports all operators including isNull and isNotNull.
|
|
226
|
-
*
|
|
227
221
|
* @param data - Array of items to filter
|
|
228
222
|
* @param filters - Array of filter options to apply
|
|
229
223
|
* @returns Filtered array
|
|
230
|
-
*
|
|
231
|
-
* @example
|
|
232
|
-
* ```typescript
|
|
233
|
-
* const items = [
|
|
234
|
-
* { id: 1, status: 'active', deletedAt: null },
|
|
235
|
-
* { id: 2, status: 'inactive', deletedAt: '2024-01-01' }
|
|
236
|
-
* ];
|
|
237
|
-
*
|
|
238
|
-
* applyFilters(items, [
|
|
239
|
-
* { field: 'status', op: 'eq', value: 'active' },
|
|
240
|
-
* { field: 'deletedAt', op: 'isNull', value: null }
|
|
241
|
-
* ]);
|
|
242
|
-
* ```
|
|
243
224
|
*/
|
|
244
225
|
function applyFilters(data, filters) {
|
|
245
226
|
return data.filter((item) => filters.every((f) => {
|
|
@@ -272,6 +253,7 @@ function applyFilters(data, filters) {
|
|
|
272
253
|
case "contains":
|
|
273
254
|
return String(v).includes(String(value));
|
|
274
255
|
case "like":
|
|
256
|
+
case "ilike":
|
|
275
257
|
return new RegExp(String(value), "i").test(String(v));
|
|
276
258
|
default:
|
|
277
259
|
return true;
|
|
@@ -280,18 +262,8 @@ function applyFilters(data, filters) {
|
|
|
280
262
|
}
|
|
281
263
|
/**
|
|
282
264
|
* Validate JSON filter structure.
|
|
283
|
-
*
|
|
284
265
|
* @param filter - Filter object to validate
|
|
285
266
|
* @throws Error if filter structure is invalid
|
|
286
|
-
*
|
|
287
|
-
* @example
|
|
288
|
-
* ```typescript
|
|
289
|
-
* // Valid filter
|
|
290
|
-
* validateJsonFilter({ status: { eq: 'active' } });
|
|
291
|
-
*
|
|
292
|
-
* // Invalid - throws error
|
|
293
|
-
* validateJsonFilter({ status: 'active' }); // Error: must have operator dictionary
|
|
294
|
-
* ```
|
|
295
267
|
*/
|
|
296
268
|
function validateJsonFilter(filter) {
|
|
297
269
|
if (typeof filter !== "object" || filter === null || Array.isArray(filter)) {
|
|
@@ -307,28 +279,15 @@ function validateJsonFilter(filter) {
|
|
|
307
279
|
}
|
|
308
280
|
const operators = fieldValue;
|
|
309
281
|
for (const [opStr, value] of Object.entries(operators)) {
|
|
310
|
-
const op =
|
|
282
|
+
const op = (0, filter_colon_utils_1.normalizeOperator)(opStr);
|
|
311
283
|
_validateFilterValue(op, value);
|
|
312
284
|
}
|
|
313
285
|
}
|
|
314
286
|
}
|
|
315
287
|
/**
|
|
316
288
|
* Convert FilterQuery to JSON filter format.
|
|
317
|
-
* Useful for serialization and debugging.
|
|
318
|
-
*
|
|
319
289
|
* @param filterQuery - FilterQuery object to convert
|
|
320
290
|
* @returns JSON filter object (e.g., {"status": {"eq": "active"}})
|
|
321
|
-
*
|
|
322
|
-
* @example
|
|
323
|
-
* ```typescript
|
|
324
|
-
* filterQueryToJson({
|
|
325
|
-
* filters: [
|
|
326
|
-
* { field: 'status', op: 'eq', value: 'active' },
|
|
327
|
-
* { field: 'age', op: 'gte', value: 18 }
|
|
328
|
-
* ]
|
|
329
|
-
* });
|
|
330
|
-
* // Returns: { status: { eq: 'active' }, age: { gte: 18 } }
|
|
331
|
-
* ```
|
|
332
291
|
*/
|
|
333
292
|
function filterQueryToJson(filterQuery) {
|
|
334
293
|
const jsonFilter = {};
|
|
@@ -344,26 +303,8 @@ function filterQueryToJson(filterQuery) {
|
|
|
344
303
|
}
|
|
345
304
|
/**
|
|
346
305
|
* Convert JSON filter format to FilterQuery.
|
|
347
|
-
* Convenience wrapper around parseFilterParams().
|
|
348
|
-
*
|
|
349
306
|
* @param jsonFilter - JSON filter object (e.g., {"status": {"eq": "active"}})
|
|
350
307
|
* @returns FilterQuery object
|
|
351
|
-
*
|
|
352
|
-
* @example
|
|
353
|
-
* ```typescript
|
|
354
|
-
* jsonToFilterQuery({
|
|
355
|
-
* status: { eq: 'active' },
|
|
356
|
-
* age: { gte: 18 },
|
|
357
|
-
* region: { in: ['eu', 'us'] }
|
|
358
|
-
* });
|
|
359
|
-
* // Returns: {
|
|
360
|
-
* // filters: [
|
|
361
|
-
* // { field: 'status', op: 'eq', value: 'active' },
|
|
362
|
-
* // { field: 'age', op: 'gte', value: 18 },
|
|
363
|
-
* // { field: 'region', op: 'in', value: ['eu', 'us'] }
|
|
364
|
-
* // ]
|
|
365
|
-
* // }
|
|
366
|
-
* ```
|
|
367
308
|
*/
|
|
368
309
|
function jsonToFilterQuery(jsonFilter) {
|
|
369
310
|
const filters = _parseJsonFilter(jsonFilter);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.utils.js","sourceRoot":"","sources":["../../src/utils/filter.utils.ts"],"names":[],"mappings":";AAAA;;GAEG;;;
|
|
1
|
+
{"version":3,"file":"filter.utils.js","sourceRoot":"","sources":["../../src/utils/filter.utils.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAyFH,8CA8FC;AAOD,4CAwBC;AASD,oCA0CC;AAOD,gDAwBC;AAOD,8CAWC;AAOD,8CAKC;AAnUD,wDAAsD;AAsU7C,8FAtUA,4BAAa,OAsUA;AArUtB,6DAA0F;AAE1F;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,EAAkB,E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,CAAC;AAED;;;;GAIG;AACH,SAAgB,iBAAiB,CAC/B,UAAmD;IAEnD,MAAM,OAAO,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAC7C,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP error handling utilities for InternalHttpClient
|
|
3
|
+
* Handles error parsing and MisoClientError creation
|
|
4
|
+
*/
|
|
5
|
+
import { AxiosError } from "axios";
|
|
6
|
+
import { ErrorResponse } from "../types/config.types";
|
|
7
|
+
import { MisoClientError } from "./errors";
|
|
8
|
+
/**
|
|
9
|
+
* Parse error response from AxiosError
|
|
10
|
+
* Attempts to parse structured ErrorResponse, falls back to null if parsing fails
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseErrorResponse(error: AxiosError, requestUrl?: string): ErrorResponse | null;
|
|
13
|
+
/**
|
|
14
|
+
* Create MisoClientError from AxiosError
|
|
15
|
+
* Parses structured error response if available, falls back to errorBody
|
|
16
|
+
*/
|
|
17
|
+
export declare function createMisoClientError(error: AxiosError, requestUrl?: string): MisoClientError;
|
|
18
|
+
/**
|
|
19
|
+
* Check if error is an AxiosError
|
|
20
|
+
*/
|
|
21
|
+
export declare function isAxiosError(error: unknown): error is AxiosError;
|
|
22
|
+
//# sourceMappingURL=http-error-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-error-handler.d.ts","sourceRoot":"","sources":["../../src/utils/http-error-handler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,aAAa,EAAmB,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,UAAU,EACjB,UAAU,CAAC,EAAE,MAAM,GAClB,aAAa,GAAG,IAAI,CAuCtB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,UAAU,EACjB,UAAU,CAAC,EAAE,MAAM,GAClB,eAAe,CAejB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAMhE"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* HTTP error handling utilities for InternalHttpClient
|
|
4
|
+
* Handles error parsing and MisoClientError creation
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.parseErrorResponse = parseErrorResponse;
|
|
8
|
+
exports.createMisoClientError = createMisoClientError;
|
|
9
|
+
exports.isAxiosError = isAxiosError;
|
|
10
|
+
const axios_1 = require("axios");
|
|
11
|
+
const config_types_1 = require("../types/config.types");
|
|
12
|
+
const errors_1 = require("./errors");
|
|
13
|
+
/**
|
|
14
|
+
* Parse error response from AxiosError
|
|
15
|
+
* Attempts to parse structured ErrorResponse, falls back to null if parsing fails
|
|
16
|
+
*/
|
|
17
|
+
function parseErrorResponse(error, requestUrl) {
|
|
18
|
+
try {
|
|
19
|
+
if (!error.response?.data)
|
|
20
|
+
return null;
|
|
21
|
+
const data = error.response.data;
|
|
22
|
+
// If data is already an object, check if it matches ErrorResponse structure
|
|
23
|
+
if (typeof data === "object" && data !== null && (0, config_types_1.isErrorResponse)(data)) {
|
|
24
|
+
return {
|
|
25
|
+
errors: data.errors,
|
|
26
|
+
type: data.type,
|
|
27
|
+
title: data.title,
|
|
28
|
+
statusCode: data.statusCode,
|
|
29
|
+
instance: data.instance || requestUrl,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// If data is a string, try to parse as JSON
|
|
33
|
+
if (typeof data === "string") {
|
|
34
|
+
try {
|
|
35
|
+
const parsed = JSON.parse(data);
|
|
36
|
+
if ((0, config_types_1.isErrorResponse)(parsed)) {
|
|
37
|
+
return {
|
|
38
|
+
errors: parsed.errors,
|
|
39
|
+
type: parsed.type,
|
|
40
|
+
title: parsed.title,
|
|
41
|
+
statusCode: parsed.statusCode,
|
|
42
|
+
instance: parsed.instance || requestUrl,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Create MisoClientError from AxiosError
|
|
58
|
+
* Parses structured error response if available, falls back to errorBody
|
|
59
|
+
*/
|
|
60
|
+
function createMisoClientError(error, requestUrl) {
|
|
61
|
+
const statusCode = error.response?.status;
|
|
62
|
+
const errorResponse = parseErrorResponse(error, requestUrl);
|
|
63
|
+
let errorBody;
|
|
64
|
+
if (error.response?.data && typeof error.response.data === "object") {
|
|
65
|
+
errorBody = error.response.data;
|
|
66
|
+
}
|
|
67
|
+
let message = error.message || "Request failed";
|
|
68
|
+
if (error.response) {
|
|
69
|
+
message = error.response.statusText || `Request failed with status code ${statusCode}`;
|
|
70
|
+
}
|
|
71
|
+
return new errors_1.MisoClientError(message, errorResponse || undefined, errorBody, statusCode);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Check if error is an AxiosError
|
|
75
|
+
*/
|
|
76
|
+
function isAxiosError(error) {
|
|
77
|
+
if (error instanceof axios_1.AxiosError)
|
|
78
|
+
return true;
|
|
79
|
+
if (typeof error === "object" && error !== null && "isAxiosError" in error) {
|
|
80
|
+
return error.isAxiosError === true;
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=http-error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-error-handler.js","sourceRoot":"","sources":["../../src/utils/http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
|
+
import { MisoClientConfig } from "../types/config.types";
|
|
6
|
+
/**
|
|
7
|
+
* Validate response structure if validation is enabled
|
|
8
|
+
* Logs warnings for validation failures but doesn't throw (non-breaking behavior)
|
|
9
|
+
* @param data - Response data to validate
|
|
10
|
+
* @param url - Request URL for error context
|
|
11
|
+
* @param config - Client configuration
|
|
12
|
+
* @returns True if validation passed or is disabled, false if validation failed
|
|
13
|
+
*/
|
|
14
|
+
export declare function validateHttpResponse(data: unknown, url: string, config: MisoClientConfig): boolean;
|
|
15
|
+
//# sourceMappingURL=http-response-validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-response-validator.d.ts","sourceRoot":"","sources":["../../src/utils/http-response-validator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,OAAO,EACb,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,gBAAgB,GACvB,OAAO,CA4CT"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* HTTP response validation utilities for InternalHttpClient
|
|
4
|
+
* Validates response structure against expected formats
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.validateHttpResponse = validateHttpResponse;
|
|
8
|
+
const response_validator_1 = require("./response-validator");
|
|
9
|
+
/**
|
|
10
|
+
* Validate response structure if validation is enabled
|
|
11
|
+
* Logs warnings for validation failures but doesn't throw (non-breaking behavior)
|
|
12
|
+
* @param data - Response data to validate
|
|
13
|
+
* @param url - Request URL for error context
|
|
14
|
+
* @param config - Client configuration
|
|
15
|
+
* @returns True if validation passed or is disabled, false if validation failed
|
|
16
|
+
*/
|
|
17
|
+
function validateHttpResponse(data, url, config) {
|
|
18
|
+
// Skip validation if explicitly disabled
|
|
19
|
+
if (config.validateResponses === false)
|
|
20
|
+
return true;
|
|
21
|
+
// Skip validation for validate token endpoint - it may return different formats
|
|
22
|
+
if (url.includes("/api/v1/auth/validate") || url.includes("/api/auth/validate")) {
|
|
23
|
+
if (data && typeof data === "object" && "data" in data) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const responseType = (0, response_validator_1.getResponseType)(data);
|
|
28
|
+
if (responseType === "unknown") {
|
|
29
|
+
console.warn(`Response validation failed for ${url}: Response structure doesn't match expected format.`, `Expected: success response ({success, data?, message?, timestamp}) or paginated response ({data[], meta, links?}).`, `Actual:`, data);
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (responseType === "success" && !(0, response_validator_1.validateSuccessResponse)(data)) {
|
|
33
|
+
console.warn(`Response validation failed for ${url}: Success response structure invalid.`, `Expected: {success: boolean, data?: T, message?: string, timestamp: string}.`, `Actual:`, data);
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
if (responseType === "paginated" && !(0, response_validator_1.validatePaginatedResponse)(data)) {
|
|
37
|
+
console.warn(`Response validation failed for ${url}: Paginated response structure invalid.`, `Expected: {data: T[], meta: {totalItems, currentPage, pageSize, type}, links?}.`, `Actual:`, data);
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=http-response-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-response-validator.js","sourceRoot":"","sources":["../../src/utils/http-response-validator.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAiBH,oDAgDC;AA/DD,6DAI8B;AAG9B;;;;;;;GAOG;AACH,SAAgB,oBAAoB,CAClC,IAAa,EACb,GAAW,EACX,MAAwB;IAExB,yCAAyC;IACzC,IAAI,MAAM,CAAC,iBAAiB,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC;IAEpD,gFAAgF;IAChF,IAAI,GAAG,CAAC,QAAQ,CAAC,uBAAuB,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,oBAAoB,CAAC,EAAE,CAAC;QAChF,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,MAAM,IAAK,IAAgC,EAAE,CAAC;YACpF,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,MAAM,YAAY,GAAG,IAAA,oCAAe,EAAC,IAAI,CAAC,CAAC;IAE3C,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC/B,OAAO,CAAC,IAAI,CACV,kCAAkC,GAAG,qDAAqD,EAC1F,oHAAoH,EACpH,SAAS,EACT,IAAI,CACL,CAAC;QACF,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,YAAY,KAAK,SAAS,IAAI,CAAC,IAAA,4CAAuB,EAAC,IAAI,CAAC,EAAE,CAAC;QACjE,OAAO,CAAC,IAAI,CACV,kCAAkC,GAAG,uCAAuC,EAC5E,8EAA8E,EAC9E,SAAS,EACT,IAAI,CACL,CAAC;QACF,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,YAAY,KAAK,WAAW,IAAI,CAAC,IAAA,8CAAyB,EAAC,IAAI,CAAC,EAAE,CAAC;QACrE,OAAO,CAAC,IAAI,CACV,kCAAkC,GAAG,yCAAyC,EAC9E,iFAAiF,EACjF,SAAS,EACT,IAAI,CACL,CAAC;QACF,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -25,6 +25,10 @@ export declare class InternalHttpClient {
|
|
|
25
25
|
* Merge two AbortSignals into one
|
|
26
26
|
*/
|
|
27
27
|
private mergeAbortSignals;
|
|
28
|
+
/**
|
|
29
|
+
* Execute axios request with timeout wrapper
|
|
30
|
+
*/
|
|
31
|
+
private executeWithTimeout;
|
|
28
32
|
/**
|
|
29
33
|
* Generate unique correlation ID for request tracking
|
|
30
34
|
*/
|
|
@@ -33,28 +37,6 @@ export declare class InternalHttpClient {
|
|
|
33
37
|
* Fetch client token from controller using clientSecret (server-side only)
|
|
34
38
|
*/
|
|
35
39
|
private fetchClientToken;
|
|
36
|
-
/**
|
|
37
|
-
* Check if error is an AxiosError (supports both instanceof and isAxiosError property)
|
|
38
|
-
*/
|
|
39
|
-
private isAxiosError;
|
|
40
|
-
/**
|
|
41
|
-
* Validate response structure if validation is enabled
|
|
42
|
-
* Logs warnings for validation failures but doesn't throw (non-breaking behavior)
|
|
43
|
-
* @param data - Response data to validate
|
|
44
|
-
* @param url - Request URL for error context
|
|
45
|
-
* @returns True if validation passed or is disabled, false if validation failed
|
|
46
|
-
*/
|
|
47
|
-
private validateResponse;
|
|
48
|
-
/**
|
|
49
|
-
* Parse error response from AxiosError
|
|
50
|
-
* Attempts to parse structured ErrorResponse, falls back to null if parsing fails
|
|
51
|
-
*/
|
|
52
|
-
private parseErrorResponse;
|
|
53
|
-
/**
|
|
54
|
-
* Create MisoClientError from AxiosError
|
|
55
|
-
* Parses structured error response if available, falls back to errorBody
|
|
56
|
-
*/
|
|
57
|
-
private createMisoClientError;
|
|
58
40
|
/**
|
|
59
41
|
* Get access to internal axios instance (for interceptors)
|
|
60
42
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal-http-client.d.ts","sourceRoot":"","sources":["../../src/utils/internal-http-client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAc,EACZ,aAAa,EACb,kBAAkB,EAInB,MAAM,OAAO,CAAC;AACf,OAAO,
|
|
1
|
+
{"version":3,"file":"internal-http-client.d.ts","sourceRoot":"","sources":["../../src/utils/internal-http-client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAc,EACZ,aAAa,EACb,kBAAkB,EAInB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,gBAAgB,EAAuB,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAM5F,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,KAAK,CAAgB;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