typedapi-client-helpers 0.1.16 → 0.2.1
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/LICENSE +21 -0
- 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 +32 -13
- package/scripts/generate-api-minimal.mjs +158 -785
- 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.js
CHANGED
|
@@ -1,42 +1,231 @@
|
|
|
1
|
+
// src/httpClient.ts
|
|
2
|
+
var ContentType = {
|
|
3
|
+
Json: "application/json",
|
|
4
|
+
JsonApi: "application/vnd.api+json",
|
|
5
|
+
FormData: "multipart/form-data",
|
|
6
|
+
UrlEncoded: "application/x-www-form-urlencoded",
|
|
7
|
+
Text: "text/plain"
|
|
8
|
+
};
|
|
9
|
+
function createApiClient(apiConfig = {}) {
|
|
10
|
+
const state = {
|
|
11
|
+
baseUrl: apiConfig.baseUrl ?? "",
|
|
12
|
+
securityData: null,
|
|
13
|
+
securityWorker: apiConfig.securityWorker,
|
|
14
|
+
customFetch: apiConfig.customFetch ?? ((...fetchParams) => fetch(...fetchParams)),
|
|
15
|
+
baseApiParams: {
|
|
16
|
+
credentials: "same-origin",
|
|
17
|
+
headers: {},
|
|
18
|
+
redirect: "follow",
|
|
19
|
+
referrerPolicy: "no-referrer",
|
|
20
|
+
...apiConfig.baseApiParams ?? {}
|
|
21
|
+
},
|
|
22
|
+
abortControllers: /* @__PURE__ */ new Map()
|
|
23
|
+
};
|
|
24
|
+
function configureApiClient2(nextConfig = {}) {
|
|
25
|
+
if (typeof nextConfig.baseUrl === "string") {
|
|
26
|
+
state.baseUrl = nextConfig.baseUrl;
|
|
27
|
+
}
|
|
28
|
+
if (nextConfig.securityWorker) {
|
|
29
|
+
state.securityWorker = nextConfig.securityWorker;
|
|
30
|
+
}
|
|
31
|
+
if (nextConfig.customFetch) {
|
|
32
|
+
state.customFetch = nextConfig.customFetch;
|
|
33
|
+
}
|
|
34
|
+
if (nextConfig.baseApiParams) {
|
|
35
|
+
state.baseApiParams = mergeRequestParams(
|
|
36
|
+
state.baseApiParams,
|
|
37
|
+
nextConfig.baseApiParams
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function setSecurityData2(data) {
|
|
42
|
+
state.securityData = data;
|
|
43
|
+
}
|
|
44
|
+
function encodeQueryParam(key, value) {
|
|
45
|
+
const encodedKey = encodeURIComponent(key);
|
|
46
|
+
const normalizedValue = value instanceof Date ? value.toISOString() : value;
|
|
47
|
+
return `${encodedKey}=${encodeURIComponent(String(normalizedValue))}`;
|
|
48
|
+
}
|
|
49
|
+
function addArrayQueryParam(key, value) {
|
|
50
|
+
return value.map((item) => encodeQueryParam(key, item)).join("&");
|
|
51
|
+
}
|
|
52
|
+
function toQueryString(rawQuery) {
|
|
53
|
+
if (!rawQuery) {
|
|
54
|
+
return "";
|
|
55
|
+
}
|
|
56
|
+
return Object.entries(rawQuery).filter(([, value]) => value !== void 0 && value !== null).map(
|
|
57
|
+
([key, value]) => Array.isArray(value) ? addArrayQueryParam(key, value) : encodeQueryParam(key, value)
|
|
58
|
+
).join("&");
|
|
59
|
+
}
|
|
60
|
+
function contentFormatter(type, input) {
|
|
61
|
+
if (input === void 0 || input === null) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
if (input instanceof FormData || input instanceof Blob) {
|
|
65
|
+
return input;
|
|
66
|
+
}
|
|
67
|
+
switch (type ?? ContentType.Json) {
|
|
68
|
+
case ContentType.Json:
|
|
69
|
+
case ContentType.JsonApi:
|
|
70
|
+
return JSON.stringify(input);
|
|
71
|
+
case ContentType.Text:
|
|
72
|
+
return typeof input === "string" ? input : JSON.stringify(input);
|
|
73
|
+
case ContentType.FormData:
|
|
74
|
+
return toFormData2(input);
|
|
75
|
+
case ContentType.UrlEncoded:
|
|
76
|
+
return toQueryString(input);
|
|
77
|
+
default:
|
|
78
|
+
return input;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function toFormData2(input) {
|
|
82
|
+
if (input instanceof FormData) {
|
|
83
|
+
return input;
|
|
84
|
+
}
|
|
85
|
+
const formData = new FormData();
|
|
86
|
+
for (const [key, value] of Object.entries(
|
|
87
|
+
input ?? {}
|
|
88
|
+
)) {
|
|
89
|
+
appendFormDataValue2(formData, key, value);
|
|
90
|
+
}
|
|
91
|
+
return formData;
|
|
92
|
+
}
|
|
93
|
+
function appendFormDataValue2(formData, key, value) {
|
|
94
|
+
if (value === void 0 || value === null) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (Array.isArray(value)) {
|
|
98
|
+
for (const item of value) {
|
|
99
|
+
appendFormDataValue2(formData, key, item);
|
|
100
|
+
}
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (value instanceof File) {
|
|
104
|
+
formData.append(key, value, value.name);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (value instanceof Blob) {
|
|
108
|
+
formData.append(key, value);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (typeof value === "object") {
|
|
112
|
+
formData.append(key, JSON.stringify(value));
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
formData.append(key, String(value));
|
|
116
|
+
}
|
|
117
|
+
function mergeRequestParams(params1, params2) {
|
|
118
|
+
return {
|
|
119
|
+
...params1,
|
|
120
|
+
...params2 ?? {},
|
|
121
|
+
headers: {
|
|
122
|
+
...params1.headers ?? {},
|
|
123
|
+
...params2?.headers ?? {}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function createAbortSignal(cancelToken) {
|
|
128
|
+
const existingAbortController = state.abortControllers.get(cancelToken);
|
|
129
|
+
if (existingAbortController) {
|
|
130
|
+
return existingAbortController.signal;
|
|
131
|
+
}
|
|
132
|
+
const abortController = new AbortController();
|
|
133
|
+
state.abortControllers.set(cancelToken, abortController);
|
|
134
|
+
return abortController.signal;
|
|
135
|
+
}
|
|
136
|
+
function abortRequest2(cancelToken) {
|
|
137
|
+
const abortController = state.abortControllers.get(cancelToken);
|
|
138
|
+
if (!abortController) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
abortController.abort();
|
|
142
|
+
state.abortControllers.delete(cancelToken);
|
|
143
|
+
}
|
|
144
|
+
async function request2({
|
|
145
|
+
body,
|
|
146
|
+
secure,
|
|
147
|
+
path,
|
|
148
|
+
type,
|
|
149
|
+
query,
|
|
150
|
+
baseUrl,
|
|
151
|
+
cancelToken,
|
|
152
|
+
...params
|
|
153
|
+
}) {
|
|
154
|
+
const secureParams = (typeof secure === "boolean" ? secure : state.baseApiParams.secure) && state.securityWorker && await state.securityWorker(state.securityData) || {};
|
|
155
|
+
const requestParams = mergeRequestParams(
|
|
156
|
+
mergeRequestParams(state.baseApiParams, params),
|
|
157
|
+
secureParams
|
|
158
|
+
);
|
|
159
|
+
const queryString = query ? toQueryString(query) : "";
|
|
160
|
+
const url = `${baseUrl ?? state.baseUrl}${path}${queryString ? `?${queryString}` : ""}`;
|
|
161
|
+
const requestInit = {
|
|
162
|
+
...requestParams,
|
|
163
|
+
headers: {
|
|
164
|
+
...requestParams.headers ?? {},
|
|
165
|
+
...type && type !== ContentType.FormData ? { "Content-Type": type } : {}
|
|
166
|
+
},
|
|
167
|
+
signal: cancelToken ? createAbortSignal(cancelToken) : requestParams.signal
|
|
168
|
+
};
|
|
169
|
+
if (body !== void 0 && body !== null) {
|
|
170
|
+
requestInit.body = contentFormatter(type, body);
|
|
171
|
+
}
|
|
172
|
+
const response = await state.customFetch(url, requestInit);
|
|
173
|
+
const typedResponse = response;
|
|
174
|
+
typedResponse.data = null;
|
|
175
|
+
typedResponse.error = null;
|
|
176
|
+
if (cancelToken) {
|
|
177
|
+
state.abortControllers.delete(cancelToken);
|
|
178
|
+
}
|
|
179
|
+
if (!response.ok) {
|
|
180
|
+
throw typedResponse;
|
|
181
|
+
}
|
|
182
|
+
return typedResponse;
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
configureApiClient: configureApiClient2,
|
|
186
|
+
setSecurityData: setSecurityData2,
|
|
187
|
+
abortRequest: abortRequest2,
|
|
188
|
+
request: request2,
|
|
189
|
+
toQueryString
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
var defaultApiClient = createApiClient();
|
|
193
|
+
var configureApiClient = defaultApiClient.configureApiClient;
|
|
194
|
+
var setSecurityData = defaultApiClient.setSecurityData;
|
|
195
|
+
var abortRequest = defaultApiClient.abortRequest;
|
|
196
|
+
var request = defaultApiClient.request;
|
|
197
|
+
|
|
1
198
|
// src/utils/buildQuery.ts
|
|
2
199
|
function buildQuery(filters, page = 1, pageSize = 100, sortBy = null, sortDirection) {
|
|
3
|
-
let isPageSizeSet = pageSize > 0;
|
|
4
200
|
const query = filters.reduce((queryResult, filter) => {
|
|
5
201
|
const { filterName, filterNameMax, type, value, maxValue, isAList } = filter;
|
|
6
|
-
if ((value
|
|
202
|
+
if (isEmptyValue(value) && isEmptyValue(maxValue)) {
|
|
7
203
|
return queryResult;
|
|
8
204
|
}
|
|
9
205
|
if (isAList && Array.isArray(value)) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
206
|
+
const convertedValues = value.map(
|
|
207
|
+
(item) => convertType(type, isOptionValue(item) ? item.value : item)
|
|
208
|
+
).filter((item) => item !== null);
|
|
209
|
+
if (convertedValues.length > 0) {
|
|
210
|
+
queryResult[filterName] = convertedValues;
|
|
15
211
|
}
|
|
16
|
-
queryResult[filterName] = value.map(
|
|
17
|
-
(item) => convertType(type, item)
|
|
18
|
-
);
|
|
19
212
|
return queryResult;
|
|
20
213
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
214
|
+
const rawValue = isOptionValue(value) ? value.value : value;
|
|
215
|
+
const convertedValue = convertType(type, rawValue);
|
|
216
|
+
if (convertedValue !== null) {
|
|
217
|
+
queryResult[filterName] = convertedValue;
|
|
26
218
|
}
|
|
27
|
-
if (filterNameMax && maxValue
|
|
219
|
+
if (filterNameMax && !isEmptyValue(maxValue)) {
|
|
28
220
|
const convertedMaxValue = convertType(type, maxValue);
|
|
29
221
|
if (convertedMaxValue !== null) {
|
|
30
222
|
queryResult[filterNameMax] = convertedMaxValue;
|
|
31
223
|
}
|
|
32
224
|
}
|
|
33
|
-
if (String(filterName) === "pageSize" && !isPageSizeSet) {
|
|
34
|
-
isPageSizeSet = true;
|
|
35
|
-
}
|
|
36
225
|
return queryResult;
|
|
37
226
|
}, {});
|
|
38
227
|
query.pageNumber = page;
|
|
39
|
-
if (
|
|
228
|
+
if (pageSize > 0) {
|
|
40
229
|
query.pageSize = pageSize;
|
|
41
230
|
}
|
|
42
231
|
if (sortBy) {
|
|
@@ -47,20 +236,43 @@ function buildQuery(filters, page = 1, pageSize = 100, sortBy = null, sortDirect
|
|
|
47
236
|
}
|
|
48
237
|
return query;
|
|
49
238
|
}
|
|
239
|
+
function isEmptyValue(value) {
|
|
240
|
+
return value === null || value === void 0 || value === "" || value === "null" || value === "undefined";
|
|
241
|
+
}
|
|
50
242
|
function isOptionValue(value) {
|
|
51
243
|
return typeof value === "object" && value !== null && "value" in value;
|
|
52
244
|
}
|
|
53
|
-
function isOptionValueArray(value) {
|
|
54
|
-
return value.every(isOptionValue);
|
|
55
|
-
}
|
|
56
245
|
function convertType(type, value) {
|
|
246
|
+
if (isEmptyValue(value)) {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
57
249
|
switch (type) {
|
|
58
|
-
case "date":
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
250
|
+
case "date": {
|
|
251
|
+
if (value instanceof Date) {
|
|
252
|
+
return Number.isNaN(value.getTime()) ? null : value.toISOString();
|
|
253
|
+
}
|
|
254
|
+
return value;
|
|
255
|
+
}
|
|
256
|
+
case "number": {
|
|
257
|
+
const numberValue = Number(value);
|
|
258
|
+
return Number.isNaN(numberValue) ? null : numberValue;
|
|
259
|
+
}
|
|
62
260
|
case "boolean":
|
|
261
|
+
case "boolean-button": {
|
|
262
|
+
if (typeof value === "boolean") {
|
|
263
|
+
return value;
|
|
264
|
+
}
|
|
265
|
+
if (typeof value === "string") {
|
|
266
|
+
const normalized = value.trim().toLowerCase();
|
|
267
|
+
if (["true", "1", "yes", "on"].includes(normalized)) {
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
270
|
+
if (["false", "0", "no", "off"].includes(normalized)) {
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
63
274
|
return Boolean(value);
|
|
275
|
+
}
|
|
64
276
|
default:
|
|
65
277
|
return value;
|
|
66
278
|
}
|
|
@@ -138,15 +350,18 @@ function extractArgsCallbacksAndParams(argsWithCallbacks) {
|
|
|
138
350
|
|
|
139
351
|
// src/utils/handleApiResponse.ts
|
|
140
352
|
async function readResponseBody(response) {
|
|
141
|
-
if (response.status === 204) {
|
|
353
|
+
if (response.status === 204 || response.status === 205) {
|
|
142
354
|
return void 0;
|
|
143
355
|
}
|
|
356
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
357
|
+
if (contentType.includes("application/octet-stream")) {
|
|
358
|
+
return response.blob();
|
|
359
|
+
}
|
|
144
360
|
const text = await response.text();
|
|
145
361
|
if (!text) {
|
|
146
362
|
return void 0;
|
|
147
363
|
}
|
|
148
|
-
|
|
149
|
-
if (contentType?.includes("application/json")) {
|
|
364
|
+
if (contentType.includes("json") || contentType.includes("+json")) {
|
|
150
365
|
try {
|
|
151
366
|
return JSON.parse(text);
|
|
152
367
|
} catch {
|
|
@@ -155,30 +370,23 @@ async function readResponseBody(response) {
|
|
|
155
370
|
}
|
|
156
371
|
return text;
|
|
157
372
|
}
|
|
373
|
+
function isResponseLike(value) {
|
|
374
|
+
return typeof value === "object" && value !== null && "status" in value && "ok" in value && "headers" in value && typeof value.text === "function";
|
|
375
|
+
}
|
|
158
376
|
async function handleApiResponse(call, options) {
|
|
159
377
|
let response;
|
|
160
378
|
try {
|
|
161
379
|
response = await call();
|
|
162
|
-
const data = await readResponseBody(response);
|
|
163
|
-
if (response.ok) {
|
|
164
|
-
const result2 = {
|
|
165
|
-
ok: true,
|
|
166
|
-
status: response.status,
|
|
167
|
-
response: data
|
|
168
|
-
};
|
|
169
|
-
await options?.onSuccess?.(result2);
|
|
170
|
-
return result2;
|
|
171
|
-
}
|
|
380
|
+
const data = await readResponseBody(response.clone());
|
|
172
381
|
const result = {
|
|
173
|
-
ok:
|
|
382
|
+
ok: true,
|
|
174
383
|
status: response.status,
|
|
175
|
-
response:
|
|
176
|
-
error: data
|
|
384
|
+
response: data
|
|
177
385
|
};
|
|
178
|
-
await options?.
|
|
386
|
+
await options?.onSuccess?.(result);
|
|
179
387
|
return result;
|
|
180
388
|
} catch (error) {
|
|
181
|
-
if (error
|
|
389
|
+
if (isResponseLike(error)) {
|
|
182
390
|
const errorData = await readResponseBody(error.clone());
|
|
183
391
|
const result2 = {
|
|
184
392
|
ok: false,
|
|
@@ -209,10 +417,14 @@ var sortTypes = [
|
|
|
209
417
|
];
|
|
210
418
|
function getSortTypeFromSortDirection(sortDirection) {
|
|
211
419
|
switch (sortDirection) {
|
|
420
|
+
case "Asc":
|
|
212
421
|
case "Ascending":
|
|
213
422
|
return "Ascending";
|
|
423
|
+
case "Desc":
|
|
214
424
|
case "Descending":
|
|
215
425
|
return "Descending";
|
|
426
|
+
case "Neutral":
|
|
427
|
+
return "Neutral";
|
|
216
428
|
case "Default":
|
|
217
429
|
default:
|
|
218
430
|
return "Default";
|
|
@@ -221,10 +433,11 @@ function getSortTypeFromSortDirection(sortDirection) {
|
|
|
221
433
|
function getSortDirectionFromSortType(sortType) {
|
|
222
434
|
switch (sortType) {
|
|
223
435
|
case "Ascending":
|
|
224
|
-
return "
|
|
436
|
+
return "Asc";
|
|
225
437
|
case "Descending":
|
|
226
|
-
return "
|
|
438
|
+
return "Desc";
|
|
227
439
|
case "Neutral":
|
|
440
|
+
return "Neutral";
|
|
228
441
|
case "Default":
|
|
229
442
|
default:
|
|
230
443
|
return "Default";
|
|
@@ -264,12 +477,19 @@ function appendFormDataValue(formData, key, value) {
|
|
|
264
477
|
formData.append(key, JSON.stringify(value));
|
|
265
478
|
}
|
|
266
479
|
export {
|
|
480
|
+
ContentType,
|
|
481
|
+
abortRequest,
|
|
267
482
|
buildQuery,
|
|
483
|
+
configureApiClient,
|
|
484
|
+
createApiClient,
|
|
485
|
+
defaultApiClient,
|
|
268
486
|
extractArgsCallbacksAndParams,
|
|
269
487
|
extractArgsToastsAndParams,
|
|
270
488
|
getSortDirectionFromSortType,
|
|
271
489
|
getSortTypeFromSortDirection,
|
|
272
490
|
handleApiResponse,
|
|
491
|
+
request,
|
|
492
|
+
setSecurityData,
|
|
273
493
|
sortTypes,
|
|
274
494
|
toFormData
|
|
275
495
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typedapi-client-helpers",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Reusable typed OpenAPI client helpers.",
|
|
5
|
+
"license": "MIT",
|
|
5
6
|
"keywords": [
|
|
6
7
|
"typescript",
|
|
7
8
|
"openapi",
|
|
@@ -20,7 +21,6 @@
|
|
|
20
21
|
"frontend",
|
|
21
22
|
"api-wrapper",
|
|
22
23
|
"generated-client",
|
|
23
|
-
"swagger-typescript-api",
|
|
24
24
|
"form-data",
|
|
25
25
|
"multipart",
|
|
26
26
|
"pagination",
|
|
@@ -28,14 +28,29 @@
|
|
|
28
28
|
"sorting"
|
|
29
29
|
],
|
|
30
30
|
"type": "module",
|
|
31
|
-
"main": "./dist/index.
|
|
31
|
+
"main": "./dist/index.cjs",
|
|
32
|
+
"module": "./dist/index.js",
|
|
32
33
|
"types": "./dist/index.d.ts",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"import": "./dist/index.js",
|
|
38
|
+
"require": "./dist/index.cjs"
|
|
39
|
+
},
|
|
40
|
+
"./package.json": "./package.json"
|
|
41
|
+
},
|
|
33
42
|
"files": [
|
|
34
43
|
"dist",
|
|
35
44
|
"scripts",
|
|
36
|
-
"
|
|
37
|
-
"
|
|
45
|
+
"README.md",
|
|
46
|
+
"LICENSE"
|
|
38
47
|
],
|
|
48
|
+
"bin": {
|
|
49
|
+
"typedapi-generate": "./scripts/generate-api-minimal.mjs"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=18"
|
|
53
|
+
},
|
|
39
54
|
"repository": {
|
|
40
55
|
"type": "git",
|
|
41
56
|
"url": "git+https://github.com/Stef-Buurman/TypedApi.git",
|
|
@@ -44,20 +59,24 @@
|
|
|
44
59
|
"homepage": "https://github.com/Stef-Buurman/TypedApi/tree/main/npm/typed-api-client#readme",
|
|
45
60
|
"config": {
|
|
46
61
|
"apiOutput": "src/api",
|
|
62
|
+
"typedApiCleanOutput": true,
|
|
63
|
+
"typedApiModuleNameFirstTag": true,
|
|
64
|
+
"typedApiUseTypeOnlyImports": true,
|
|
47
65
|
"typedApiDefaultFunctionsPath": "src/defaultApiFunctions",
|
|
48
66
|
"typedApiDefaultSuccessHandler": "handleGoodResult",
|
|
49
|
-
"typedApiDefaultErrorHandler": "handleErrors"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
67
|
+
"typedApiDefaultErrorHandler": "handleErrors",
|
|
68
|
+
"typedApiDefaultResponseAsSuccess": false,
|
|
69
|
+
"typedApiGenerateUnionEnums": false,
|
|
70
|
+
"typedApiEnumNamesAsValues": false,
|
|
71
|
+
"typedApiSwaggerBackupFile": "swagger/swagger.backup.json"
|
|
53
72
|
},
|
|
54
73
|
"scripts": {
|
|
55
|
-
"
|
|
74
|
+
"clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
75
|
+
"typecheck": "tsc --noEmit",
|
|
76
|
+
"build": "npm run clean && tsup src/index.ts --format esm,cjs --dts",
|
|
77
|
+
"prepack": "npm run typecheck && npm run build",
|
|
56
78
|
"generate:api": "node ./scripts/generate-api-minimal.mjs"
|
|
57
79
|
},
|
|
58
|
-
"dependencies": {
|
|
59
|
-
"swagger-typescript-api": "^13.2.16"
|
|
60
|
-
},
|
|
61
80
|
"devDependencies": {
|
|
62
81
|
"tsup": "^8.5.1",
|
|
63
82
|
"typescript": "5.8.3"
|