typedapi-client-helpers 0.1.15 → 0.2.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/README.md +220 -490
- package/dist/index.cjs +274 -47
- package/dist/index.d.cts +79 -95
- package/dist/index.d.ts +79 -95
- package/dist/index.js +267 -47
- package/package.json +54 -12
- package/scripts/generate-api-minimal.mjs +476 -959
- package/scripts/openapi-generator/controller-template.mjs +246 -0
- package/scripts/openapi-generator/http-client-template.mjs +34 -0
- package/scripts/openapi-generator/index.mjs +113 -0
- package/scripts/openapi-generator/method-template.mjs +440 -0
- package/scripts/openapi-generator/names.mjs +145 -0
- package/scripts/openapi-generator/openapi-utils.mjs +147 -0
- package/scripts/openapi-generator/schema.mjs +455 -0
- package/bin/typedapi-generate.js +0 -3
- package/dist/api/generated/Import.d.ts +0 -22
- package/dist/api/generated/Import.d.ts.map +0 -1
- package/dist/api/generated/Import.js +0 -48
- package/dist/api/generated/Import.js.map +0 -1
- package/dist/api/generated/ImportRoute.d.ts +0 -30
- package/dist/api/generated/ImportRoute.d.ts.map +0 -1
- package/dist/api/generated/ImportRoute.js +0 -13
- package/dist/api/generated/ImportRoute.js.map +0 -1
- package/dist/api/generated/Order.d.ts +0 -38
- package/dist/api/generated/Order.d.ts.map +0 -1
- package/dist/api/generated/Order.js +0 -75
- package/dist/api/generated/Order.js.map +0 -1
- package/dist/api/generated/OrderRoute.d.ts +0 -83
- package/dist/api/generated/OrderRoute.d.ts.map +0 -1
- package/dist/api/generated/OrderRoute.js +0 -13
- package/dist/api/generated/OrderRoute.js.map +0 -1
- package/dist/api/generated/Product.d.ts +0 -62
- package/dist/api/generated/Product.d.ts.map +0 -1
- package/dist/api/generated/Product.js +0 -114
- package/dist/api/generated/Product.js.map +0 -1
- package/dist/api/generated/ProductRoute.d.ts +0 -140
- package/dist/api/generated/ProductRoute.d.ts.map +0 -1
- package/dist/api/generated/ProductRoute.js +0 -13
- package/dist/api/generated/ProductRoute.js.map +0 -1
- package/dist/api/generated/Report.d.ts +0 -14
- package/dist/api/generated/Report.d.ts.map +0 -1
- package/dist/api/generated/Report.js +0 -32
- package/dist/api/generated/Report.js.map +0 -1
- package/dist/api/generated/ReportRoute.d.ts +0 -23
- package/dist/api/generated/ReportRoute.d.ts.map +0 -1
- package/dist/api/generated/ReportRoute.js +0 -13
- package/dist/api/generated/ReportRoute.js.map +0 -1
- package/dist/api/generated/Supplier.d.ts +0 -46
- package/dist/api/generated/Supplier.d.ts.map +0 -1
- package/dist/api/generated/Supplier.js +0 -87
- package/dist/api/generated/Supplier.js.map +0 -1
- package/dist/api/generated/SupplierRoute.d.ts +0 -101
- package/dist/api/generated/SupplierRoute.d.ts.map +0 -1
- package/dist/api/generated/SupplierRoute.js +0 -13
- package/dist/api/generated/SupplierRoute.js.map +0 -1
- package/dist/api/generated/data-contracts.d.ts +0 -277
- package/dist/api/generated/data-contracts.d.ts.map +0 -1
- package/dist/api/generated/data-contracts.js +0 -26
- package/dist/api/generated/data-contracts.js.map +0 -1
- package/dist/api/generated/http-client.d.ts +0 -61
- package/dist/api/generated/http-client.d.ts.map +0 -1
- package/dist/api/generated/http-client.js +0 -171
- package/dist/api/generated/http-client.js.map +0 -1
- package/dist/api/index.d.ts +0 -8
- package/dist/api/index.d.ts.map +0 -1
- package/dist/api/index.js +0 -8
- package/dist/api/index.js.map +0 -1
- package/dist/api/methods/Import.api.d.ts +0 -6
- package/dist/api/methods/Import.api.d.ts.map +0 -1
- package/dist/api/methods/Import.api.js +0 -27
- package/dist/api/methods/Import.api.js.map +0 -1
- package/dist/api/methods/Order.api.d.ts +0 -29
- package/dist/api/methods/Order.api.d.ts.map +0 -1
- package/dist/api/methods/Order.api.js +0 -52
- package/dist/api/methods/Order.api.js.map +0 -1
- package/dist/api/methods/Product.api.d.ts +0 -39
- package/dist/api/methods/Product.api.d.ts.map +0 -1
- package/dist/api/methods/Product.api.js +0 -69
- package/dist/api/methods/Product.api.js.map +0 -1
- package/dist/api/methods/Report.api.d.ts +0 -6
- package/dist/api/methods/Report.api.d.ts.map +0 -1
- package/dist/api/methods/Report.api.js +0 -19
- package/dist/api/methods/Report.api.js.map +0 -1
- package/dist/api/methods/Supplier.api.d.ts +0 -35
- package/dist/api/methods/Supplier.api.d.ts.map +0 -1
- package/dist/api/methods/Supplier.api.js +0 -63
- package/dist/api/methods/Supplier.api.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/interfaces/ApiResult.d.ts +0 -17
- package/dist/interfaces/ApiResult.d.ts.map +0 -1
- package/dist/interfaces/ApiResult.js +0 -2
- package/dist/interfaces/ApiResult.js.map +0 -1
- package/dist/interfaces/Filter.d.ts +0 -31
- package/dist/interfaces/Filter.d.ts.map +0 -1
- package/dist/interfaces/Filter.js +0 -2
- package/dist/interfaces/Filter.js.map +0 -1
- package/dist/interfaces/SortType.d.ts +0 -7
- package/dist/interfaces/SortType.d.ts.map +0 -1
- package/dist/interfaces/SortType.js +0 -2
- package/dist/interfaces/SortType.js.map +0 -1
- package/dist/types/ApiCallOptions.d.ts +0 -9
- package/dist/types/ApiCallOptions.d.ts.map +0 -1
- package/dist/types/ApiCallOptions.js +0 -2
- package/dist/types/ApiCallOptions.js.map +0 -1
- package/dist/types/ApiMethodTypes.d.ts +0 -24
- package/dist/types/ApiMethodTypes.d.ts.map +0 -1
- package/dist/types/ApiMethodTypes.js +0 -2
- package/dist/types/ApiMethodTypes.js.map +0 -1
- package/dist/types/HttpResponse.d.ts +0 -16
- package/dist/types/HttpResponse.d.ts.map +0 -1
- package/dist/types/HttpResponse.js +0 -2
- package/dist/types/HttpResponse.js.map +0 -1
- package/dist/utils/SortTypeFromSortDirection.d.ts +0 -22
- package/dist/utils/SortTypeFromSortDirection.d.ts.map +0 -1
- package/dist/utils/SortTypeFromSortDirection.js +0 -45
- package/dist/utils/SortTypeFromSortDirection.js.map +0 -1
- package/dist/utils/buildQuery.d.ts +0 -11
- package/dist/utils/buildQuery.d.ts.map +0 -1
- package/dist/utils/buildQuery.js +0 -94
- package/dist/utils/buildQuery.js.map +0 -1
- package/dist/utils/extractArgsCallbacksAndParams.d.ts +0 -22
- package/dist/utils/extractArgsCallbacksAndParams.d.ts.map +0 -1
- package/dist/utils/extractArgsCallbacksAndParams.js +0 -44
- package/dist/utils/extractArgsCallbacksAndParams.js.map +0 -1
- package/dist/utils/extractArgsToastsAndParams.d.ts +0 -18
- package/dist/utils/extractArgsToastsAndParams.d.ts.map +0 -1
- package/dist/utils/extractArgsToastsAndParams.js +0 -40
- package/dist/utils/extractArgsToastsAndParams.js.map +0 -1
- package/dist/utils/handleApiResponse.d.ts +0 -9
- package/dist/utils/handleApiResponse.d.ts.map +0 -1
- package/dist/utils/handleApiResponse.js +0 -49
- package/dist/utils/handleApiResponse.js.map +0 -1
- package/dist/utils/toFormData.d.ts +0 -8
- package/dist/utils/toFormData.d.ts.map +0 -1
- package/dist/utils/toFormData.js +0 -68
- package/dist/utils/toFormData.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -20,56 +20,252 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
ContentType: () => ContentType,
|
|
24
|
+
abortRequest: () => abortRequest,
|
|
23
25
|
buildQuery: () => buildQuery,
|
|
26
|
+
configureApiClient: () => configureApiClient,
|
|
27
|
+
createApiClient: () => createApiClient,
|
|
28
|
+
defaultApiClient: () => defaultApiClient,
|
|
24
29
|
extractArgsCallbacksAndParams: () => extractArgsCallbacksAndParams,
|
|
25
30
|
extractArgsToastsAndParams: () => extractArgsToastsAndParams,
|
|
26
31
|
getSortDirectionFromSortType: () => getSortDirectionFromSortType,
|
|
27
32
|
getSortTypeFromSortDirection: () => getSortTypeFromSortDirection,
|
|
28
33
|
handleApiResponse: () => handleApiResponse,
|
|
34
|
+
request: () => request,
|
|
35
|
+
setSecurityData: () => setSecurityData,
|
|
29
36
|
sortTypes: () => sortTypes,
|
|
30
37
|
toFormData: () => toFormData
|
|
31
38
|
});
|
|
32
39
|
module.exports = __toCommonJS(index_exports);
|
|
33
40
|
|
|
41
|
+
// src/httpClient.ts
|
|
42
|
+
var ContentType = {
|
|
43
|
+
Json: "application/json",
|
|
44
|
+
JsonApi: "application/vnd.api+json",
|
|
45
|
+
FormData: "multipart/form-data",
|
|
46
|
+
UrlEncoded: "application/x-www-form-urlencoded",
|
|
47
|
+
Text: "text/plain"
|
|
48
|
+
};
|
|
49
|
+
function createApiClient(apiConfig = {}) {
|
|
50
|
+
const state = {
|
|
51
|
+
baseUrl: apiConfig.baseUrl ?? "",
|
|
52
|
+
securityData: null,
|
|
53
|
+
securityWorker: apiConfig.securityWorker,
|
|
54
|
+
customFetch: apiConfig.customFetch ?? ((...fetchParams) => fetch(...fetchParams)),
|
|
55
|
+
baseApiParams: {
|
|
56
|
+
credentials: "same-origin",
|
|
57
|
+
headers: {},
|
|
58
|
+
redirect: "follow",
|
|
59
|
+
referrerPolicy: "no-referrer",
|
|
60
|
+
...apiConfig.baseApiParams ?? {}
|
|
61
|
+
},
|
|
62
|
+
abortControllers: /* @__PURE__ */ new Map()
|
|
63
|
+
};
|
|
64
|
+
function configureApiClient2(nextConfig = {}) {
|
|
65
|
+
if (typeof nextConfig.baseUrl === "string") {
|
|
66
|
+
state.baseUrl = nextConfig.baseUrl;
|
|
67
|
+
}
|
|
68
|
+
if (nextConfig.securityWorker) {
|
|
69
|
+
state.securityWorker = nextConfig.securityWorker;
|
|
70
|
+
}
|
|
71
|
+
if (nextConfig.customFetch) {
|
|
72
|
+
state.customFetch = nextConfig.customFetch;
|
|
73
|
+
}
|
|
74
|
+
if (nextConfig.baseApiParams) {
|
|
75
|
+
state.baseApiParams = mergeRequestParams(
|
|
76
|
+
state.baseApiParams,
|
|
77
|
+
nextConfig.baseApiParams
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function setSecurityData2(data) {
|
|
82
|
+
state.securityData = data;
|
|
83
|
+
}
|
|
84
|
+
function encodeQueryParam(key, value) {
|
|
85
|
+
const encodedKey = encodeURIComponent(key);
|
|
86
|
+
const normalizedValue = value instanceof Date ? value.toISOString() : value;
|
|
87
|
+
return `${encodedKey}=${encodeURIComponent(String(normalizedValue))}`;
|
|
88
|
+
}
|
|
89
|
+
function addArrayQueryParam(key, value) {
|
|
90
|
+
return value.map((item) => encodeQueryParam(key, item)).join("&");
|
|
91
|
+
}
|
|
92
|
+
function toQueryString(rawQuery) {
|
|
93
|
+
if (!rawQuery) {
|
|
94
|
+
return "";
|
|
95
|
+
}
|
|
96
|
+
return Object.entries(rawQuery).filter(([, value]) => value !== void 0 && value !== null).map(
|
|
97
|
+
([key, value]) => Array.isArray(value) ? addArrayQueryParam(key, value) : encodeQueryParam(key, value)
|
|
98
|
+
).join("&");
|
|
99
|
+
}
|
|
100
|
+
function contentFormatter(type, input) {
|
|
101
|
+
if (input === void 0 || input === null) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
if (input instanceof FormData || input instanceof Blob) {
|
|
105
|
+
return input;
|
|
106
|
+
}
|
|
107
|
+
switch (type ?? ContentType.Json) {
|
|
108
|
+
case ContentType.Json:
|
|
109
|
+
case ContentType.JsonApi:
|
|
110
|
+
return JSON.stringify(input);
|
|
111
|
+
case ContentType.Text:
|
|
112
|
+
return typeof input === "string" ? input : JSON.stringify(input);
|
|
113
|
+
case ContentType.FormData:
|
|
114
|
+
return toFormData2(input);
|
|
115
|
+
case ContentType.UrlEncoded:
|
|
116
|
+
return toQueryString(input);
|
|
117
|
+
default:
|
|
118
|
+
return input;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function toFormData2(input) {
|
|
122
|
+
if (input instanceof FormData) {
|
|
123
|
+
return input;
|
|
124
|
+
}
|
|
125
|
+
const formData = new FormData();
|
|
126
|
+
for (const [key, value] of Object.entries(
|
|
127
|
+
input ?? {}
|
|
128
|
+
)) {
|
|
129
|
+
appendFormDataValue2(formData, key, value);
|
|
130
|
+
}
|
|
131
|
+
return formData;
|
|
132
|
+
}
|
|
133
|
+
function appendFormDataValue2(formData, key, value) {
|
|
134
|
+
if (value === void 0 || value === null) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (Array.isArray(value)) {
|
|
138
|
+
for (const item of value) {
|
|
139
|
+
appendFormDataValue2(formData, key, item);
|
|
140
|
+
}
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (value instanceof File) {
|
|
144
|
+
formData.append(key, value, value.name);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (value instanceof Blob) {
|
|
148
|
+
formData.append(key, value);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (typeof value === "object") {
|
|
152
|
+
formData.append(key, JSON.stringify(value));
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
formData.append(key, String(value));
|
|
156
|
+
}
|
|
157
|
+
function mergeRequestParams(params1, params2) {
|
|
158
|
+
return {
|
|
159
|
+
...params1,
|
|
160
|
+
...params2 ?? {},
|
|
161
|
+
headers: {
|
|
162
|
+
...params1.headers ?? {},
|
|
163
|
+
...params2?.headers ?? {}
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function createAbortSignal(cancelToken) {
|
|
168
|
+
const existingAbortController = state.abortControllers.get(cancelToken);
|
|
169
|
+
if (existingAbortController) {
|
|
170
|
+
return existingAbortController.signal;
|
|
171
|
+
}
|
|
172
|
+
const abortController = new AbortController();
|
|
173
|
+
state.abortControllers.set(cancelToken, abortController);
|
|
174
|
+
return abortController.signal;
|
|
175
|
+
}
|
|
176
|
+
function abortRequest2(cancelToken) {
|
|
177
|
+
const abortController = state.abortControllers.get(cancelToken);
|
|
178
|
+
if (!abortController) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
abortController.abort();
|
|
182
|
+
state.abortControllers.delete(cancelToken);
|
|
183
|
+
}
|
|
184
|
+
async function request2({
|
|
185
|
+
body,
|
|
186
|
+
secure,
|
|
187
|
+
path,
|
|
188
|
+
type,
|
|
189
|
+
query,
|
|
190
|
+
baseUrl,
|
|
191
|
+
cancelToken,
|
|
192
|
+
...params
|
|
193
|
+
}) {
|
|
194
|
+
const secureParams = (typeof secure === "boolean" ? secure : state.baseApiParams.secure) && state.securityWorker && await state.securityWorker(state.securityData) || {};
|
|
195
|
+
const requestParams = mergeRequestParams(
|
|
196
|
+
mergeRequestParams(state.baseApiParams, params),
|
|
197
|
+
secureParams
|
|
198
|
+
);
|
|
199
|
+
const queryString = query ? toQueryString(query) : "";
|
|
200
|
+
const url = `${baseUrl ?? state.baseUrl}${path}${queryString ? `?${queryString}` : ""}`;
|
|
201
|
+
const requestInit = {
|
|
202
|
+
...requestParams,
|
|
203
|
+
headers: {
|
|
204
|
+
...requestParams.headers ?? {},
|
|
205
|
+
...type && type !== ContentType.FormData ? { "Content-Type": type } : {}
|
|
206
|
+
},
|
|
207
|
+
signal: cancelToken ? createAbortSignal(cancelToken) : requestParams.signal
|
|
208
|
+
};
|
|
209
|
+
if (body !== void 0 && body !== null) {
|
|
210
|
+
requestInit.body = contentFormatter(type, body);
|
|
211
|
+
}
|
|
212
|
+
const response = await state.customFetch(url, requestInit);
|
|
213
|
+
const typedResponse = response;
|
|
214
|
+
typedResponse.data = null;
|
|
215
|
+
typedResponse.error = null;
|
|
216
|
+
if (cancelToken) {
|
|
217
|
+
state.abortControllers.delete(cancelToken);
|
|
218
|
+
}
|
|
219
|
+
if (!response.ok) {
|
|
220
|
+
throw typedResponse;
|
|
221
|
+
}
|
|
222
|
+
return typedResponse;
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
configureApiClient: configureApiClient2,
|
|
226
|
+
setSecurityData: setSecurityData2,
|
|
227
|
+
abortRequest: abortRequest2,
|
|
228
|
+
request: request2,
|
|
229
|
+
toQueryString
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
var defaultApiClient = createApiClient();
|
|
233
|
+
var configureApiClient = defaultApiClient.configureApiClient;
|
|
234
|
+
var setSecurityData = defaultApiClient.setSecurityData;
|
|
235
|
+
var abortRequest = defaultApiClient.abortRequest;
|
|
236
|
+
var request = defaultApiClient.request;
|
|
237
|
+
|
|
34
238
|
// src/utils/buildQuery.ts
|
|
35
239
|
function buildQuery(filters, page = 1, pageSize = 100, sortBy = null, sortDirection) {
|
|
36
|
-
let isPageSizeSet = pageSize > 0;
|
|
37
240
|
const query = filters.reduce((queryResult, filter) => {
|
|
38
241
|
const { filterName, filterNameMax, type, value, maxValue, isAList } = filter;
|
|
39
|
-
if ((value
|
|
242
|
+
if (isEmptyValue(value) && isEmptyValue(maxValue)) {
|
|
40
243
|
return queryResult;
|
|
41
244
|
}
|
|
42
245
|
if (isAList && Array.isArray(value)) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
246
|
+
const convertedValues = value.map(
|
|
247
|
+
(item) => convertType(type, isOptionValue(item) ? item.value : item)
|
|
248
|
+
).filter((item) => item !== null);
|
|
249
|
+
if (convertedValues.length > 0) {
|
|
250
|
+
queryResult[filterName] = convertedValues;
|
|
48
251
|
}
|
|
49
|
-
queryResult[filterName] = value.map(
|
|
50
|
-
(item) => convertType(type, item)
|
|
51
|
-
);
|
|
52
252
|
return queryResult;
|
|
53
253
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
254
|
+
const rawValue = isOptionValue(value) ? value.value : value;
|
|
255
|
+
const convertedValue = convertType(type, rawValue);
|
|
256
|
+
if (convertedValue !== null) {
|
|
257
|
+
queryResult[filterName] = convertedValue;
|
|
59
258
|
}
|
|
60
|
-
if (filterNameMax && maxValue
|
|
259
|
+
if (filterNameMax && !isEmptyValue(maxValue)) {
|
|
61
260
|
const convertedMaxValue = convertType(type, maxValue);
|
|
62
261
|
if (convertedMaxValue !== null) {
|
|
63
262
|
queryResult[filterNameMax] = convertedMaxValue;
|
|
64
263
|
}
|
|
65
264
|
}
|
|
66
|
-
if (String(filterName) === "pageSize" && !isPageSizeSet) {
|
|
67
|
-
isPageSizeSet = true;
|
|
68
|
-
}
|
|
69
265
|
return queryResult;
|
|
70
266
|
}, {});
|
|
71
267
|
query.pageNumber = page;
|
|
72
|
-
if (
|
|
268
|
+
if (pageSize > 0) {
|
|
73
269
|
query.pageSize = pageSize;
|
|
74
270
|
}
|
|
75
271
|
if (sortBy) {
|
|
@@ -80,20 +276,43 @@ function buildQuery(filters, page = 1, pageSize = 100, sortBy = null, sortDirect
|
|
|
80
276
|
}
|
|
81
277
|
return query;
|
|
82
278
|
}
|
|
279
|
+
function isEmptyValue(value) {
|
|
280
|
+
return value === null || value === void 0 || value === "" || value === "null" || value === "undefined";
|
|
281
|
+
}
|
|
83
282
|
function isOptionValue(value) {
|
|
84
283
|
return typeof value === "object" && value !== null && "value" in value;
|
|
85
284
|
}
|
|
86
|
-
function isOptionValueArray(value) {
|
|
87
|
-
return value.every(isOptionValue);
|
|
88
|
-
}
|
|
89
285
|
function convertType(type, value) {
|
|
286
|
+
if (isEmptyValue(value)) {
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
90
289
|
switch (type) {
|
|
91
|
-
case "date":
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
290
|
+
case "date": {
|
|
291
|
+
if (value instanceof Date) {
|
|
292
|
+
return Number.isNaN(value.getTime()) ? null : value.toISOString();
|
|
293
|
+
}
|
|
294
|
+
return value;
|
|
295
|
+
}
|
|
296
|
+
case "number": {
|
|
297
|
+
const numberValue = Number(value);
|
|
298
|
+
return Number.isNaN(numberValue) ? null : numberValue;
|
|
299
|
+
}
|
|
95
300
|
case "boolean":
|
|
301
|
+
case "boolean-button": {
|
|
302
|
+
if (typeof value === "boolean") {
|
|
303
|
+
return value;
|
|
304
|
+
}
|
|
305
|
+
if (typeof value === "string") {
|
|
306
|
+
const normalized = value.trim().toLowerCase();
|
|
307
|
+
if (["true", "1", "yes", "on"].includes(normalized)) {
|
|
308
|
+
return true;
|
|
309
|
+
}
|
|
310
|
+
if (["false", "0", "no", "off"].includes(normalized)) {
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
96
314
|
return Boolean(value);
|
|
315
|
+
}
|
|
97
316
|
default:
|
|
98
317
|
return value;
|
|
99
318
|
}
|
|
@@ -171,15 +390,18 @@ function extractArgsCallbacksAndParams(argsWithCallbacks) {
|
|
|
171
390
|
|
|
172
391
|
// src/utils/handleApiResponse.ts
|
|
173
392
|
async function readResponseBody(response) {
|
|
174
|
-
if (response.status === 204) {
|
|
393
|
+
if (response.status === 204 || response.status === 205) {
|
|
175
394
|
return void 0;
|
|
176
395
|
}
|
|
396
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
397
|
+
if (contentType.includes("application/octet-stream")) {
|
|
398
|
+
return response.blob();
|
|
399
|
+
}
|
|
177
400
|
const text = await response.text();
|
|
178
401
|
if (!text) {
|
|
179
402
|
return void 0;
|
|
180
403
|
}
|
|
181
|
-
|
|
182
|
-
if (contentType?.includes("application/json")) {
|
|
404
|
+
if (contentType.includes("json") || contentType.includes("+json")) {
|
|
183
405
|
try {
|
|
184
406
|
return JSON.parse(text);
|
|
185
407
|
} catch {
|
|
@@ -188,30 +410,23 @@ async function readResponseBody(response) {
|
|
|
188
410
|
}
|
|
189
411
|
return text;
|
|
190
412
|
}
|
|
413
|
+
function isResponseLike(value) {
|
|
414
|
+
return typeof value === "object" && value !== null && "status" in value && "ok" in value && "headers" in value && typeof value.text === "function";
|
|
415
|
+
}
|
|
191
416
|
async function handleApiResponse(call, options) {
|
|
192
417
|
let response;
|
|
193
418
|
try {
|
|
194
419
|
response = await call();
|
|
195
|
-
const data = await readResponseBody(response);
|
|
196
|
-
if (response.ok) {
|
|
197
|
-
const result2 = {
|
|
198
|
-
ok: true,
|
|
199
|
-
status: response.status,
|
|
200
|
-
response: data
|
|
201
|
-
};
|
|
202
|
-
await options?.onSuccess?.(result2);
|
|
203
|
-
return result2;
|
|
204
|
-
}
|
|
420
|
+
const data = await readResponseBody(response.clone());
|
|
205
421
|
const result = {
|
|
206
|
-
ok:
|
|
422
|
+
ok: true,
|
|
207
423
|
status: response.status,
|
|
208
|
-
response:
|
|
209
|
-
error: data
|
|
424
|
+
response: data
|
|
210
425
|
};
|
|
211
|
-
await options?.
|
|
426
|
+
await options?.onSuccess?.(result);
|
|
212
427
|
return result;
|
|
213
428
|
} catch (error) {
|
|
214
|
-
if (error
|
|
429
|
+
if (isResponseLike(error)) {
|
|
215
430
|
const errorData = await readResponseBody(error.clone());
|
|
216
431
|
const result2 = {
|
|
217
432
|
ok: false,
|
|
@@ -242,10 +457,14 @@ var sortTypes = [
|
|
|
242
457
|
];
|
|
243
458
|
function getSortTypeFromSortDirection(sortDirection) {
|
|
244
459
|
switch (sortDirection) {
|
|
460
|
+
case "Asc":
|
|
245
461
|
case "Ascending":
|
|
246
462
|
return "Ascending";
|
|
463
|
+
case "Desc":
|
|
247
464
|
case "Descending":
|
|
248
465
|
return "Descending";
|
|
466
|
+
case "Neutral":
|
|
467
|
+
return "Neutral";
|
|
249
468
|
case "Default":
|
|
250
469
|
default:
|
|
251
470
|
return "Default";
|
|
@@ -254,10 +473,11 @@ function getSortTypeFromSortDirection(sortDirection) {
|
|
|
254
473
|
function getSortDirectionFromSortType(sortType) {
|
|
255
474
|
switch (sortType) {
|
|
256
475
|
case "Ascending":
|
|
257
|
-
return "
|
|
476
|
+
return "Asc";
|
|
258
477
|
case "Descending":
|
|
259
|
-
return "
|
|
478
|
+
return "Desc";
|
|
260
479
|
case "Neutral":
|
|
480
|
+
return "Neutral";
|
|
261
481
|
case "Default":
|
|
262
482
|
default:
|
|
263
483
|
return "Default";
|
|
@@ -298,12 +518,19 @@ function appendFormDataValue(formData, key, value) {
|
|
|
298
518
|
}
|
|
299
519
|
// Annotate the CommonJS export names for ESM import in node:
|
|
300
520
|
0 && (module.exports = {
|
|
521
|
+
ContentType,
|
|
522
|
+
abortRequest,
|
|
301
523
|
buildQuery,
|
|
524
|
+
configureApiClient,
|
|
525
|
+
createApiClient,
|
|
526
|
+
defaultApiClient,
|
|
302
527
|
extractArgsCallbacksAndParams,
|
|
303
528
|
extractArgsToastsAndParams,
|
|
304
529
|
getSortDirectionFromSortType,
|
|
305
530
|
getSortTypeFromSortDirection,
|
|
306
531
|
handleApiResponse,
|
|
532
|
+
request,
|
|
533
|
+
setSecurityData,
|
|
307
534
|
sortTypes,
|
|
308
535
|
toFormData
|
|
309
536
|
});
|