@exyconn/common 2.3.2 → 2.3.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/README.md +117 -12
- package/dist/client/http/index.d.mts +217 -49
- package/dist/client/http/index.d.ts +217 -49
- package/dist/client/http/index.js +473 -94
- package/dist/client/http/index.js.map +1 -1
- package/dist/client/http/index.mjs +441 -84
- package/dist/client/http/index.mjs.map +1 -1
- package/dist/client/index.d.mts +3 -3
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.js +481 -319
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +449 -290
- package/dist/client/index.mjs.map +1 -1
- package/dist/client/utils/index.d.mts +3 -279
- package/dist/client/utils/index.d.ts +3 -279
- package/dist/{index-DuxL84IW.d.mts → index-BZf42T3R.d.mts} +39 -39
- package/dist/{index-D9a9oxQy.d.ts → index-CF0D8PGE.d.ts} +39 -39
- package/dist/{index-D3yCCjBZ.d.mts → index-Ckhm_HaX.d.mts} +21 -2
- package/dist/{index-01hoqibP.d.ts → index-br6POSyA.d.ts} +21 -2
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1122 -329
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1134 -341
- package/dist/index.mjs.map +1 -1
- package/dist/packageCheck-B_qfsD6R.d.ts +280 -0
- package/dist/packageCheck-C2_FT_Rl.d.mts +280 -0
- package/dist/server/index.d.mts +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +631 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +625 -2
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/middleware/index.d.mts +283 -2
- package/dist/server/middleware/index.d.ts +283 -2
- package/dist/server/middleware/index.js +761 -0
- package/dist/server/middleware/index.js.map +1 -1
- package/dist/server/middleware/index.mjs +751 -1
- package/dist/server/middleware/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1,109 +1,466 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
|
|
3
|
-
// src/client/http/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
3
|
+
// src/client/http/http.ts
|
|
4
|
+
|
|
5
|
+
// src/client/http/logger.ts
|
|
6
|
+
var Logger = class {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.isDevelopment = typeof window !== "undefined" && window.location.hostname === "localhost";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Log informational messages
|
|
12
|
+
*/
|
|
13
|
+
info(message, data, options) {
|
|
14
|
+
if (this.isDevelopment) {
|
|
15
|
+
const prefix = options?.context ? `[${options.context}]` : "";
|
|
16
|
+
console.log(`${prefix} ${message}`, data ?? "");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Log warning messages
|
|
21
|
+
*/
|
|
22
|
+
warn(message, data, options) {
|
|
23
|
+
if (this.isDevelopment) {
|
|
24
|
+
const prefix = options?.context ? `[${options.context}]` : "";
|
|
25
|
+
console.warn(`${prefix} ${message}`, data ?? "");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Log error messages
|
|
30
|
+
*/
|
|
31
|
+
error(message, error, options) {
|
|
32
|
+
const prefix = options?.context ? `[${options.context}]` : "";
|
|
33
|
+
if (this.isDevelopment) {
|
|
34
|
+
console.error(`${prefix} ${message}`, error, options?.metadata || "");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Log debug messages (only in development)
|
|
39
|
+
*/
|
|
40
|
+
debug(message, data, options) {
|
|
41
|
+
if (this.isDevelopment) {
|
|
42
|
+
const prefix = options?.context ? `[${options.context}]` : "";
|
|
43
|
+
console.debug(`${prefix} ${message}`, data || "");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Log API errors with structured information
|
|
48
|
+
*/
|
|
49
|
+
apiError(endpoint, error, metadata) {
|
|
50
|
+
this.error(`API Error: ${endpoint}`, error, {
|
|
51
|
+
context: "API",
|
|
52
|
+
metadata: {
|
|
53
|
+
endpoint,
|
|
54
|
+
...metadata
|
|
28
55
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var logger = new Logger();
|
|
60
|
+
|
|
61
|
+
// src/client/http/response-parser.ts
|
|
62
|
+
var STATUS_CODES = {
|
|
63
|
+
SUCCESS: 200,
|
|
64
|
+
CREATED: 201,
|
|
65
|
+
NO_CONTENT: 204,
|
|
66
|
+
BAD_REQUEST: 400,
|
|
67
|
+
UNAUTHORIZED: 401,
|
|
68
|
+
FORBIDDEN: 403,
|
|
69
|
+
NOT_FOUND: 404,
|
|
70
|
+
CONFLICT: 409,
|
|
71
|
+
ERROR: 500
|
|
72
|
+
};
|
|
73
|
+
var STATUS_MESSAGES = {
|
|
74
|
+
SUCCESS: "success",
|
|
75
|
+
CREATED: "created",
|
|
76
|
+
NO_CONTENT: "no_content",
|
|
77
|
+
BAD_REQUEST: "bad_request",
|
|
78
|
+
UNAUTHORIZED: "unauthorized",
|
|
79
|
+
FORBIDDEN: "forbidden",
|
|
80
|
+
NOT_FOUND: "not_found",
|
|
81
|
+
CONFLICT: "conflict",
|
|
82
|
+
ERROR: "error"
|
|
83
|
+
};
|
|
84
|
+
var SUCCESS_CODES = [200, 201, 204];
|
|
85
|
+
var ERROR_CODES = [400, 401, 403, 404, 409, 500];
|
|
86
|
+
var parseResponseData = (response, fallback = null) => {
|
|
87
|
+
try {
|
|
88
|
+
if (!response || typeof response !== "object") {
|
|
89
|
+
return fallback;
|
|
90
|
+
}
|
|
91
|
+
const resp = response;
|
|
92
|
+
if ("data" in resp) {
|
|
93
|
+
return resp["data"] ?? fallback;
|
|
94
|
+
}
|
|
95
|
+
return response;
|
|
96
|
+
} catch (error) {
|
|
97
|
+
logger.error("Error parsing response data", error);
|
|
98
|
+
return fallback;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
var parseResponseMessage = (response, fallback = "") => {
|
|
102
|
+
try {
|
|
103
|
+
if (!response || typeof response !== "object") {
|
|
104
|
+
return fallback;
|
|
105
|
+
}
|
|
106
|
+
const resp = response;
|
|
107
|
+
if ("message" in resp && typeof resp["message"] === "string") {
|
|
108
|
+
return resp["message"];
|
|
109
|
+
}
|
|
110
|
+
return fallback;
|
|
111
|
+
} catch (error) {
|
|
112
|
+
logger.error("Error parsing response message", error);
|
|
113
|
+
return fallback;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
var parseResponseStatus = (response) => {
|
|
117
|
+
try {
|
|
118
|
+
if (!response || typeof response !== "object") {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
const resp = response;
|
|
122
|
+
if ("statusCode" in resp && typeof resp["statusCode"] === "number") {
|
|
123
|
+
return resp["statusCode"];
|
|
124
|
+
}
|
|
125
|
+
if ("status" in resp && typeof resp["status"] === "number") {
|
|
126
|
+
return resp["status"];
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
} catch (error) {
|
|
130
|
+
logger.error("Error parsing response status", error);
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
var parseResponseStatusMessage = (response, fallback = "") => {
|
|
135
|
+
try {
|
|
136
|
+
if (!response || typeof response !== "object") {
|
|
137
|
+
return fallback;
|
|
138
|
+
}
|
|
139
|
+
const resp = response;
|
|
140
|
+
if ("status" in resp && typeof resp["status"] === "string") {
|
|
141
|
+
return resp["status"];
|
|
142
|
+
}
|
|
143
|
+
return fallback;
|
|
144
|
+
} catch (error) {
|
|
145
|
+
logger.error("Error parsing response status message", error);
|
|
146
|
+
return fallback;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
var isSuccessResponse = (response) => {
|
|
150
|
+
try {
|
|
151
|
+
const statusCode = parseResponseStatus(response);
|
|
152
|
+
if (statusCode !== null) {
|
|
153
|
+
return SUCCESS_CODES.includes(statusCode);
|
|
154
|
+
}
|
|
155
|
+
const status = parseResponseStatusMessage(response);
|
|
156
|
+
return [STATUS_MESSAGES.SUCCESS, STATUS_MESSAGES.CREATED, STATUS_MESSAGES.NO_CONTENT].includes(
|
|
157
|
+
status
|
|
158
|
+
);
|
|
159
|
+
} catch (error) {
|
|
160
|
+
logger.error("Error checking response success", error);
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
var isErrorResponse = (response) => {
|
|
165
|
+
try {
|
|
166
|
+
const statusCode = parseResponseStatus(response);
|
|
167
|
+
if (statusCode !== null) {
|
|
168
|
+
return ERROR_CODES.includes(statusCode);
|
|
169
|
+
}
|
|
170
|
+
return false;
|
|
171
|
+
} catch (error) {
|
|
172
|
+
logger.error("Error checking response error", error);
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
var parsePaginatedResponse = (response) => {
|
|
177
|
+
try {
|
|
178
|
+
if (!response || typeof response !== "object") {
|
|
179
|
+
return { items: [], total: 0, page: 1, limit: 10 };
|
|
180
|
+
}
|
|
181
|
+
const resp = response;
|
|
182
|
+
let items = [];
|
|
183
|
+
if ("data" in resp && Array.isArray(resp["data"])) {
|
|
184
|
+
items = resp["data"];
|
|
185
|
+
}
|
|
186
|
+
let total = items.length;
|
|
187
|
+
let page = 1;
|
|
188
|
+
let limit = 10;
|
|
189
|
+
let totalPages;
|
|
190
|
+
if ("paginationData" in resp && resp["paginationData"] && typeof resp["paginationData"] === "object") {
|
|
191
|
+
const paginationData = resp["paginationData"];
|
|
192
|
+
if ("total" in paginationData && typeof paginationData["total"] === "number") {
|
|
193
|
+
total = paginationData["total"];
|
|
194
|
+
}
|
|
195
|
+
if ("page" in paginationData && typeof paginationData["page"] === "number") {
|
|
196
|
+
page = paginationData["page"];
|
|
197
|
+
}
|
|
198
|
+
if ("limit" in paginationData && typeof paginationData["limit"] === "number") {
|
|
199
|
+
limit = paginationData["limit"];
|
|
200
|
+
}
|
|
201
|
+
if ("totalPages" in paginationData && typeof paginationData["totalPages"] === "number") {
|
|
202
|
+
totalPages = paginationData["totalPages"];
|
|
44
203
|
}
|
|
45
|
-
return Promise.reject(error);
|
|
46
204
|
}
|
|
47
|
-
|
|
48
|
-
|
|
205
|
+
let columns;
|
|
206
|
+
if ("columns" in resp && Array.isArray(resp["columns"])) {
|
|
207
|
+
columns = resp["columns"];
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
items,
|
|
211
|
+
total,
|
|
212
|
+
page,
|
|
213
|
+
limit,
|
|
214
|
+
...totalPages !== void 0 && { totalPages },
|
|
215
|
+
...columns !== void 0 && { columns }
|
|
216
|
+
};
|
|
217
|
+
} catch (error) {
|
|
218
|
+
logger.error("Error parsing paginated response", error);
|
|
219
|
+
return { items: [], total: 0, page: 1, limit: 10 };
|
|
220
|
+
}
|
|
49
221
|
};
|
|
50
|
-
var
|
|
51
|
-
|
|
52
|
-
|
|
222
|
+
var extractNestedData = (response, path, fallback = null) => {
|
|
223
|
+
try {
|
|
224
|
+
const keys = path.split(".");
|
|
225
|
+
let current = response;
|
|
226
|
+
for (const key of keys) {
|
|
227
|
+
if (current && typeof current === "object" && key in current) {
|
|
228
|
+
current = current[key];
|
|
229
|
+
} else {
|
|
230
|
+
return fallback;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return current;
|
|
234
|
+
} catch (error) {
|
|
235
|
+
logger.error("Error extracting nested data", error);
|
|
236
|
+
return fallback;
|
|
53
237
|
}
|
|
54
|
-
}
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
// src/client/http/response-parser.ts
|
|
63
|
-
var parseResponse = (response) => {
|
|
64
|
-
if (response.data?.success && response.data?.data !== void 0) {
|
|
65
|
-
return response.data.data;
|
|
238
|
+
};
|
|
239
|
+
var safeJsonParse = (json, fallback = null) => {
|
|
240
|
+
try {
|
|
241
|
+
return JSON.parse(json);
|
|
242
|
+
} catch (error) {
|
|
243
|
+
logger.error("Error parsing JSON", error);
|
|
244
|
+
return fallback;
|
|
66
245
|
}
|
|
67
|
-
return null;
|
|
68
246
|
};
|
|
69
|
-
var
|
|
70
|
-
|
|
247
|
+
var parseAxiosErrorMessage = (error) => {
|
|
248
|
+
try {
|
|
249
|
+
if (!error || typeof error !== "object") {
|
|
250
|
+
return "An unexpected error occurred";
|
|
251
|
+
}
|
|
252
|
+
const err = error;
|
|
253
|
+
if ("response" in err && err["response"] && typeof err["response"] === "object") {
|
|
254
|
+
const response = err["response"];
|
|
255
|
+
if ("data" in response && response["data"] && typeof response["data"] === "object") {
|
|
256
|
+
const data = response["data"];
|
|
257
|
+
if ("data" in data && data["data"] && typeof data["data"] === "object") {
|
|
258
|
+
const nestedData = data["data"];
|
|
259
|
+
if ("message" in nestedData && typeof nestedData["message"] === "string") {
|
|
260
|
+
return nestedData["message"];
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if ("message" in data && typeof data["message"] === "string") {
|
|
264
|
+
return data["message"];
|
|
265
|
+
}
|
|
266
|
+
if ("error" in data && typeof data["error"] === "string") {
|
|
267
|
+
return data["error"];
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if ("message" in err && typeof err["message"] === "string") {
|
|
272
|
+
return err["message"];
|
|
273
|
+
}
|
|
274
|
+
if (typeof error === "string") {
|
|
275
|
+
return error;
|
|
276
|
+
}
|
|
277
|
+
return "An unexpected error occurred";
|
|
278
|
+
} catch (parseError2) {
|
|
279
|
+
logger.error("Error parsing axios error message", parseError2);
|
|
280
|
+
return "An unexpected error occurred";
|
|
281
|
+
}
|
|
71
282
|
};
|
|
72
283
|
var parseError = (error) => {
|
|
73
|
-
|
|
74
|
-
|
|
284
|
+
try {
|
|
285
|
+
if (!error || typeof error !== "object") {
|
|
286
|
+
return {
|
|
287
|
+
message: "An unexpected error occurred",
|
|
288
|
+
statusCode: null,
|
|
289
|
+
data: null
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
const err = error;
|
|
293
|
+
let statusCode = null;
|
|
294
|
+
let data = null;
|
|
295
|
+
let status;
|
|
296
|
+
if ("response" in err && err["response"] && typeof err["response"] === "object") {
|
|
297
|
+
const response = err["response"];
|
|
298
|
+
if ("status" in response && typeof response["status"] === "number") {
|
|
299
|
+
statusCode = response["status"];
|
|
300
|
+
}
|
|
301
|
+
if ("data" in response && response["data"] !== void 0) {
|
|
302
|
+
data = response["data"];
|
|
303
|
+
if (data && typeof data === "object" && "status" in data) {
|
|
304
|
+
const dataObj = data;
|
|
305
|
+
if (typeof dataObj["status"] === "string") {
|
|
306
|
+
status = dataObj["status"];
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (statusCode === null && "statusCode" in err && typeof err["statusCode"] === "number") {
|
|
312
|
+
statusCode = err["statusCode"];
|
|
313
|
+
}
|
|
314
|
+
if (data === null && "data" in err && err["data"] !== void 0) {
|
|
315
|
+
data = err["data"];
|
|
316
|
+
}
|
|
317
|
+
if (!status && "status" in err && typeof err["status"] === "string") {
|
|
318
|
+
status = err["status"];
|
|
319
|
+
}
|
|
320
|
+
return {
|
|
321
|
+
message: parseAxiosErrorMessage(error),
|
|
322
|
+
statusCode,
|
|
323
|
+
data,
|
|
324
|
+
...status !== void 0 && { status }
|
|
325
|
+
};
|
|
326
|
+
} catch (err) {
|
|
327
|
+
logger.error("Error parsing error object", err);
|
|
328
|
+
return {
|
|
329
|
+
message: "An unexpected error occurred",
|
|
330
|
+
statusCode: null,
|
|
331
|
+
data: null
|
|
332
|
+
};
|
|
75
333
|
}
|
|
76
|
-
|
|
77
|
-
|
|
334
|
+
};
|
|
335
|
+
var simpleParseResponse = (response) => {
|
|
336
|
+
return response?.data?.data?.data;
|
|
337
|
+
};
|
|
338
|
+
var simpleMetaParseResponse = (response) => {
|
|
339
|
+
return response?.data?.data?.meta;
|
|
340
|
+
};
|
|
341
|
+
var simpleParseDualDataResponse = (response) => {
|
|
342
|
+
return response?.data?.data;
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
// src/client/http/http.ts
|
|
346
|
+
var isDevelopment = typeof window !== "undefined" && window.location.hostname === "localhost";
|
|
347
|
+
var API_BASE_URL = isDevelopment ? "http://localhost:4002" : "https://service-api.exyconn.com";
|
|
348
|
+
var API_PREFIX = "/v1/api";
|
|
349
|
+
var axiosInstance = axios.create({
|
|
350
|
+
baseURL: API_BASE_URL,
|
|
351
|
+
timeout: 3e4,
|
|
352
|
+
// 30 seconds
|
|
353
|
+
headers: {
|
|
354
|
+
"Content-Type": "application/json"
|
|
78
355
|
}
|
|
79
|
-
|
|
80
|
-
|
|
356
|
+
});
|
|
357
|
+
axiosInstance.interceptors.request.use(
|
|
358
|
+
(config) => {
|
|
359
|
+
try {
|
|
360
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
361
|
+
const selectedOrg = localStorage.getItem("selectedOrganization");
|
|
362
|
+
if (selectedOrg) {
|
|
363
|
+
const org = JSON.parse(selectedOrg);
|
|
364
|
+
if (org && org._id) {
|
|
365
|
+
config.headers["x-organization-id"] = org._id;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
} catch (error) {
|
|
370
|
+
logger.warn("Failed to read organization from localStorage", error);
|
|
371
|
+
}
|
|
372
|
+
return config;
|
|
373
|
+
},
|
|
374
|
+
(error) => {
|
|
375
|
+
return Promise.reject(error);
|
|
81
376
|
}
|
|
82
|
-
|
|
83
|
-
|
|
377
|
+
);
|
|
378
|
+
axiosInstance.interceptors.response.use(
|
|
379
|
+
(response) => response,
|
|
380
|
+
(error) => {
|
|
381
|
+
const parsedError = parseError(error);
|
|
382
|
+
logger.error("API Error", parsedError);
|
|
383
|
+
return Promise.reject(parsedError);
|
|
84
384
|
}
|
|
85
|
-
|
|
385
|
+
);
|
|
386
|
+
var buildHeaders = (customHeaders) => {
|
|
387
|
+
const headers = {
|
|
388
|
+
"Content-Type": "application/json",
|
|
389
|
+
...customHeaders
|
|
390
|
+
};
|
|
391
|
+
return headers;
|
|
86
392
|
};
|
|
87
|
-
var
|
|
88
|
-
|
|
393
|
+
var buildConfig = (params, customHeaders) => {
|
|
394
|
+
const config = {
|
|
395
|
+
headers: buildHeaders(customHeaders)
|
|
396
|
+
};
|
|
397
|
+
if (params) {
|
|
398
|
+
config.params = params;
|
|
399
|
+
}
|
|
400
|
+
return config;
|
|
401
|
+
};
|
|
402
|
+
var getRequest = async (url, params, customHeaders) => {
|
|
403
|
+
const config = buildConfig(params, customHeaders);
|
|
404
|
+
return axiosInstance.get(url, config);
|
|
89
405
|
};
|
|
90
|
-
var
|
|
91
|
-
|
|
406
|
+
var postRequest = async (url, data, customHeaders) => {
|
|
407
|
+
const config = buildConfig(void 0, customHeaders);
|
|
408
|
+
return axiosInstance.post(url, data, config);
|
|
92
409
|
};
|
|
93
|
-
var
|
|
94
|
-
|
|
410
|
+
var putRequest = async (url, data, customHeaders) => {
|
|
411
|
+
const config = buildConfig(void 0, customHeaders);
|
|
412
|
+
return axiosInstance.put(url, data, config);
|
|
95
413
|
};
|
|
96
|
-
var
|
|
97
|
-
|
|
414
|
+
var patchRequest = async (url, data, customHeaders) => {
|
|
415
|
+
const config = buildConfig(void 0, customHeaders);
|
|
416
|
+
return axiosInstance.patch(url, data, config);
|
|
417
|
+
};
|
|
418
|
+
var deleteRequest = async (url, params, customHeaders) => {
|
|
419
|
+
const config = buildConfig(params, customHeaders);
|
|
420
|
+
return axiosInstance.delete(url, config);
|
|
421
|
+
};
|
|
422
|
+
var uploadFile = async (url, file, additionalData) => {
|
|
423
|
+
const formData = new FormData();
|
|
424
|
+
formData.append("file", file);
|
|
425
|
+
if (additionalData) {
|
|
426
|
+
Object.entries(additionalData).forEach(([key, value]) => {
|
|
427
|
+
formData.append(key, String(value));
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
const config = {
|
|
431
|
+
headers: {
|
|
432
|
+
"Content-Type": "multipart/form-data"
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
return axiosInstance.post(url, formData, config);
|
|
436
|
+
};
|
|
437
|
+
var extractData = (response) => {
|
|
438
|
+
return parseResponseData(response.data);
|
|
439
|
+
};
|
|
440
|
+
var extractMessage = (response) => {
|
|
441
|
+
return parseResponseMessage(response, "");
|
|
442
|
+
};
|
|
443
|
+
var isSuccess = (response) => {
|
|
444
|
+
return response.status >= 200 && response.status < 300;
|
|
445
|
+
};
|
|
446
|
+
var extractPaginatedData = (response) => {
|
|
447
|
+
return parsePaginatedResponse(response.data);
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
// src/client/http/slug.ts
|
|
451
|
+
var generateSlug = (text) => {
|
|
452
|
+
if (!text) return "";
|
|
453
|
+
return text.trim().replace(/[^\w\s]/g, "").replace(/\s+(.)/g, (_, char) => char.toUpperCase()).replace(/\s+/g, "").replace(/^(.)/, (_, char) => char.toLowerCase());
|
|
98
454
|
};
|
|
99
|
-
var
|
|
100
|
-
|
|
455
|
+
var generateUrlSlug = (text) => {
|
|
456
|
+
if (!text) return "";
|
|
457
|
+
return text.trim().toLowerCase().replace(/[^\w\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
101
458
|
};
|
|
102
|
-
var
|
|
103
|
-
|
|
104
|
-
return
|
|
459
|
+
var generateSnakeSlug = (text) => {
|
|
460
|
+
if (!text) return "";
|
|
461
|
+
return text.trim().toLowerCase().replace(/[^\w\s]/g, "").replace(/\s+/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "");
|
|
105
462
|
};
|
|
106
463
|
|
|
107
|
-
export {
|
|
464
|
+
export { API_BASE_URL, API_PREFIX, ERROR_CODES, STATUS_CODES, STATUS_MESSAGES, SUCCESS_CODES, axiosInstance as axios, deleteRequest, extractData, extractMessage, extractNestedData, extractPaginatedData, generateSlug, generateSnakeSlug, generateUrlSlug, getRequest, isErrorResponse, isSuccess, isSuccessResponse, logger, parseAxiosErrorMessage, parseError, parsePaginatedResponse, parseResponseData, parseResponseMessage, parseResponseStatus, parseResponseStatusMessage, patchRequest, postRequest, putRequest, safeJsonParse, simpleMetaParseResponse, simpleParseDualDataResponse, simpleParseResponse, uploadFile };
|
|
108
465
|
//# sourceMappingURL=index.mjs.map
|
|
109
466
|
//# sourceMappingURL=index.mjs.map
|