@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,85 +1,253 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as axios from 'axios';
|
|
2
|
+
import { AxiosResponse } from 'axios';
|
|
3
|
+
export { AxiosError, AxiosResponse } from 'axios';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
|
-
*
|
|
6
|
+
* Response Parser Utility
|
|
7
|
+
*
|
|
8
|
+
* Comprehensive response parsing utilities for API responses.
|
|
9
|
+
* Aligned with server-side response structures.
|
|
5
10
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Standard API response structure from server
|
|
13
|
+
*/
|
|
14
|
+
interface ApiResponse<T = unknown> {
|
|
15
|
+
message: string;
|
|
16
|
+
data: T | null;
|
|
17
|
+
status: string;
|
|
18
|
+
statusCode: number;
|
|
19
|
+
paginationData?: PaginationData;
|
|
20
|
+
columns?: ColumnMetadata[];
|
|
13
21
|
}
|
|
14
22
|
/**
|
|
15
|
-
*
|
|
23
|
+
* Pagination metadata structure
|
|
16
24
|
*/
|
|
17
|
-
|
|
25
|
+
interface PaginationData {
|
|
26
|
+
total?: number;
|
|
27
|
+
page?: number;
|
|
28
|
+
limit?: number;
|
|
29
|
+
totalPages?: number;
|
|
30
|
+
}
|
|
18
31
|
/**
|
|
19
|
-
*
|
|
32
|
+
* Column metadata from server
|
|
20
33
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
34
|
+
interface ColumnMetadata {
|
|
35
|
+
name: string;
|
|
36
|
+
required: boolean;
|
|
37
|
+
datatype: string;
|
|
38
|
+
}
|
|
25
39
|
/**
|
|
26
|
-
*
|
|
40
|
+
* Status codes aligned with backend
|
|
27
41
|
*/
|
|
28
|
-
|
|
29
|
-
|
|
42
|
+
declare const STATUS_CODES: {
|
|
43
|
+
readonly SUCCESS: 200;
|
|
44
|
+
readonly CREATED: 201;
|
|
45
|
+
readonly NO_CONTENT: 204;
|
|
46
|
+
readonly BAD_REQUEST: 400;
|
|
47
|
+
readonly UNAUTHORIZED: 401;
|
|
48
|
+
readonly FORBIDDEN: 403;
|
|
49
|
+
readonly NOT_FOUND: 404;
|
|
50
|
+
readonly CONFLICT: 409;
|
|
51
|
+
readonly ERROR: 500;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Status messages aligned with backend
|
|
55
|
+
*/
|
|
56
|
+
declare const STATUS_MESSAGES: {
|
|
57
|
+
SUCCESS: string;
|
|
58
|
+
CREATED: string;
|
|
59
|
+
NO_CONTENT: string;
|
|
60
|
+
BAD_REQUEST: string;
|
|
61
|
+
UNAUTHORIZED: string;
|
|
62
|
+
FORBIDDEN: string;
|
|
63
|
+
NOT_FOUND: string;
|
|
64
|
+
CONFLICT: string;
|
|
65
|
+
ERROR: string;
|
|
66
|
+
};
|
|
67
|
+
declare const SUCCESS_CODES: number[];
|
|
68
|
+
declare const ERROR_CODES: number[];
|
|
69
|
+
/**
|
|
70
|
+
* Safely extracts data from API response
|
|
71
|
+
*/
|
|
72
|
+
declare const parseResponseData: <T = unknown>(response: unknown, fallback?: T | null) => T | null;
|
|
73
|
+
/**
|
|
74
|
+
* Extracts message from response
|
|
75
|
+
*/
|
|
76
|
+
declare const parseResponseMessage: (response: unknown, fallback?: string) => string;
|
|
77
|
+
/**
|
|
78
|
+
* Extracts status code from response
|
|
79
|
+
*/
|
|
80
|
+
declare const parseResponseStatus: (response: unknown) => number | null;
|
|
81
|
+
/**
|
|
82
|
+
* Extracts status message from response
|
|
83
|
+
*/
|
|
84
|
+
declare const parseResponseStatusMessage: (response: unknown, fallback?: string) => string;
|
|
85
|
+
/**
|
|
86
|
+
* Checks if response indicates success
|
|
87
|
+
*/
|
|
88
|
+
declare const isSuccessResponse: (response: unknown) => boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Checks if response indicates error
|
|
91
|
+
*/
|
|
92
|
+
declare const isErrorResponse: (response: unknown) => boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Paginated response structure
|
|
95
|
+
*/
|
|
96
|
+
interface PaginatedResponse<T> {
|
|
97
|
+
items: T[];
|
|
98
|
+
total: number;
|
|
99
|
+
page: number;
|
|
100
|
+
limit: number;
|
|
101
|
+
totalPages?: number;
|
|
102
|
+
columns?: ColumnMetadata[];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Parses paginated response from backend
|
|
106
|
+
*/
|
|
107
|
+
declare const parsePaginatedResponse: <T = unknown>(response: unknown) => PaginatedResponse<T>;
|
|
108
|
+
/**
|
|
109
|
+
* Extracts specific nested data with path
|
|
110
|
+
*/
|
|
111
|
+
declare const extractNestedData: <T = unknown>(response: unknown, path: string, fallback?: T | null) => T | null;
|
|
112
|
+
/**
|
|
113
|
+
* Safe JSON parse with fallback
|
|
114
|
+
*/
|
|
115
|
+
declare const safeJsonParse: <T = unknown>(json: string, fallback?: T | null) => T | null;
|
|
116
|
+
/**
|
|
117
|
+
* Extracts error message from axios error response
|
|
118
|
+
*/
|
|
119
|
+
declare const parseAxiosErrorMessage: (error: unknown) => string;
|
|
120
|
+
/**
|
|
121
|
+
* Standardized error object
|
|
122
|
+
*/
|
|
123
|
+
interface ParsedError {
|
|
30
124
|
message: string;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
125
|
+
statusCode: number | null;
|
|
126
|
+
data: unknown;
|
|
127
|
+
status?: string;
|
|
34
128
|
}
|
|
35
129
|
/**
|
|
36
|
-
*
|
|
130
|
+
* Parses error into standardized format
|
|
37
131
|
*/
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
hasPrevPage: boolean;
|
|
132
|
+
declare const parseError: (error: unknown) => ParsedError;
|
|
133
|
+
interface SimpleApiResponse {
|
|
134
|
+
data?: {
|
|
135
|
+
data?: {
|
|
136
|
+
data?: unknown;
|
|
137
|
+
meta?: Record<string, unknown>;
|
|
138
|
+
};
|
|
46
139
|
};
|
|
47
140
|
}
|
|
141
|
+
declare const simpleParseResponse: (response: SimpleApiResponse) => unknown;
|
|
142
|
+
declare const simpleMetaParseResponse: (response: SimpleApiResponse) => Record<string, unknown> | undefined;
|
|
143
|
+
declare const simpleParseDualDataResponse: (response: SimpleApiResponse) => {
|
|
144
|
+
data?: unknown;
|
|
145
|
+
meta?: Record<string, unknown>;
|
|
146
|
+
} | undefined;
|
|
147
|
+
|
|
148
|
+
declare const API_BASE_URL: string;
|
|
149
|
+
declare const API_PREFIX = "/v1/api";
|
|
150
|
+
declare const axiosInstance: axios.AxiosInstance;
|
|
151
|
+
/**
|
|
152
|
+
* GET request
|
|
153
|
+
*/
|
|
154
|
+
declare const getRequest: <T = unknown>(url: string, params?: Record<string, unknown>, customHeaders?: Record<string, string>) => Promise<AxiosResponse<T>>;
|
|
155
|
+
/**
|
|
156
|
+
* POST request
|
|
157
|
+
*/
|
|
158
|
+
declare const postRequest: <T = unknown>(url: string, data?: unknown, customHeaders?: Record<string, string>) => Promise<AxiosResponse<T>>;
|
|
159
|
+
/**
|
|
160
|
+
* PUT request
|
|
161
|
+
*/
|
|
162
|
+
declare const putRequest: <T = unknown>(url: string, data?: unknown, customHeaders?: Record<string, string>) => Promise<AxiosResponse<T>>;
|
|
163
|
+
/**
|
|
164
|
+
* PATCH request
|
|
165
|
+
*/
|
|
166
|
+
declare const patchRequest: <T = unknown>(url: string, data?: unknown, customHeaders?: Record<string, string>) => Promise<AxiosResponse<T>>;
|
|
167
|
+
/**
|
|
168
|
+
* DELETE request
|
|
169
|
+
*/
|
|
170
|
+
declare const deleteRequest: <T = unknown>(url: string, params?: Record<string, unknown>, customHeaders?: Record<string, string>) => Promise<AxiosResponse<T>>;
|
|
48
171
|
/**
|
|
49
|
-
*
|
|
172
|
+
* File upload with FormData
|
|
50
173
|
*/
|
|
51
|
-
declare const
|
|
174
|
+
declare const uploadFile: <T = unknown>(url: string, file: File, additionalData?: Record<string, unknown>) => Promise<AxiosResponse<T>>;
|
|
52
175
|
/**
|
|
53
|
-
*
|
|
176
|
+
* Extract data from response using response-parser
|
|
54
177
|
*/
|
|
55
|
-
declare const
|
|
178
|
+
declare const extractData: <T = unknown>(response: AxiosResponse) => T | null;
|
|
56
179
|
/**
|
|
57
|
-
*
|
|
180
|
+
* Extract message from response
|
|
58
181
|
*/
|
|
59
|
-
declare const
|
|
182
|
+
declare const extractMessage: (response: unknown) => string;
|
|
60
183
|
/**
|
|
61
184
|
* Check if response is successful
|
|
62
185
|
*/
|
|
63
|
-
declare const isSuccess:
|
|
186
|
+
declare const isSuccess: (response: AxiosResponse) => boolean;
|
|
64
187
|
/**
|
|
65
|
-
*
|
|
188
|
+
* Extract paginated data from response
|
|
189
|
+
*/
|
|
190
|
+
declare const extractPaginatedData: <T = unknown>(response: AxiosResponse) => PaginatedResponse<T>;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Slug Utility
|
|
194
|
+
*
|
|
195
|
+
* Generates slugs from text for use in URLs and object properties.
|
|
66
196
|
*/
|
|
67
|
-
declare const isStatusError: (error: AxiosError, statusCode: number) => boolean;
|
|
68
197
|
/**
|
|
69
|
-
*
|
|
198
|
+
* Generates a camelCase slug from a given text for use in object properties
|
|
199
|
+
* @param text - The text to convert to camelCase slug
|
|
200
|
+
* @returns The generated camelCase slug
|
|
70
201
|
*/
|
|
71
|
-
declare const
|
|
202
|
+
declare const generateSlug: (text: string) => string;
|
|
72
203
|
/**
|
|
73
|
-
*
|
|
204
|
+
* Generates a kebab-case slug from a given text for use in URLs
|
|
205
|
+
* @param text - The text to convert to kebab-case slug
|
|
206
|
+
* @returns The generated kebab-case slug
|
|
74
207
|
*/
|
|
75
|
-
declare const
|
|
208
|
+
declare const generateUrlSlug: (text: string) => string;
|
|
76
209
|
/**
|
|
77
|
-
*
|
|
210
|
+
* Generates a snake_case slug from a given text
|
|
211
|
+
* @param text - The text to convert to snake_case slug
|
|
212
|
+
* @returns The generated snake_case slug
|
|
78
213
|
*/
|
|
79
|
-
declare const
|
|
214
|
+
declare const generateSnakeSlug: (text: string) => string;
|
|
215
|
+
|
|
80
216
|
/**
|
|
81
|
-
*
|
|
217
|
+
* Client Logger Utility
|
|
218
|
+
*
|
|
219
|
+
* Centralized logging utility that:
|
|
220
|
+
* - Only logs in development mode
|
|
221
|
+
* - Can be extended to send logs to external services (Sentry, LogRocket, etc.)
|
|
222
|
+
* - Provides consistent logging interface
|
|
82
223
|
*/
|
|
83
|
-
|
|
224
|
+
interface LogOptions {
|
|
225
|
+
context?: string;
|
|
226
|
+
metadata?: Record<string, unknown>;
|
|
227
|
+
}
|
|
228
|
+
declare class Logger {
|
|
229
|
+
private isDevelopment;
|
|
230
|
+
/**
|
|
231
|
+
* Log informational messages
|
|
232
|
+
*/
|
|
233
|
+
info(message: string, data?: unknown, options?: LogOptions): void;
|
|
234
|
+
/**
|
|
235
|
+
* Log warning messages
|
|
236
|
+
*/
|
|
237
|
+
warn(message: string, data?: unknown, options?: LogOptions): void;
|
|
238
|
+
/**
|
|
239
|
+
* Log error messages
|
|
240
|
+
*/
|
|
241
|
+
error(message: string, error?: unknown, options?: LogOptions): void;
|
|
242
|
+
/**
|
|
243
|
+
* Log debug messages (only in development)
|
|
244
|
+
*/
|
|
245
|
+
debug(message: string, data?: unknown, options?: LogOptions): void;
|
|
246
|
+
/**
|
|
247
|
+
* Log API errors with structured information
|
|
248
|
+
*/
|
|
249
|
+
apiError(endpoint: string, error: unknown, metadata?: Record<string, unknown>): void;
|
|
250
|
+
}
|
|
251
|
+
declare const logger: Logger;
|
|
84
252
|
|
|
85
|
-
export { type ApiResponse, type
|
|
253
|
+
export { API_BASE_URL, API_PREFIX, type ApiResponse, type ColumnMetadata, ERROR_CODES, type PaginatedResponse, type PaginationData, type ParsedError, 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 };
|