typedapi-client-helpers 0.1.4 → 0.1.6

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.
Files changed (129) hide show
  1. package/README.md +314 -167
  2. package/dist/api/generated/Import.d.ts +22 -0
  3. package/dist/api/generated/Import.d.ts.map +1 -0
  4. package/dist/api/generated/Import.js +48 -0
  5. package/dist/api/generated/Import.js.map +1 -0
  6. package/dist/api/generated/ImportRoute.d.ts +30 -0
  7. package/dist/api/generated/ImportRoute.d.ts.map +1 -0
  8. package/dist/api/generated/ImportRoute.js +13 -0
  9. package/dist/api/generated/ImportRoute.js.map +1 -0
  10. package/dist/api/generated/Order.d.ts +38 -0
  11. package/dist/api/generated/Order.d.ts.map +1 -0
  12. package/dist/api/generated/Order.js +75 -0
  13. package/dist/api/generated/Order.js.map +1 -0
  14. package/dist/api/generated/OrderRoute.d.ts +83 -0
  15. package/dist/api/generated/OrderRoute.d.ts.map +1 -0
  16. package/dist/api/generated/OrderRoute.js +13 -0
  17. package/dist/api/generated/OrderRoute.js.map +1 -0
  18. package/dist/api/generated/Product.d.ts +62 -0
  19. package/dist/api/generated/Product.d.ts.map +1 -0
  20. package/dist/api/generated/Product.js +114 -0
  21. package/dist/api/generated/Product.js.map +1 -0
  22. package/dist/api/generated/ProductRoute.d.ts +140 -0
  23. package/dist/api/generated/ProductRoute.d.ts.map +1 -0
  24. package/dist/api/generated/ProductRoute.js +13 -0
  25. package/dist/api/generated/ProductRoute.js.map +1 -0
  26. package/dist/api/generated/Report.d.ts +14 -0
  27. package/dist/api/generated/Report.d.ts.map +1 -0
  28. package/dist/api/generated/Report.js +32 -0
  29. package/dist/api/generated/Report.js.map +1 -0
  30. package/dist/api/generated/ReportRoute.d.ts +23 -0
  31. package/dist/api/generated/ReportRoute.d.ts.map +1 -0
  32. package/dist/api/generated/ReportRoute.js +13 -0
  33. package/dist/api/generated/ReportRoute.js.map +1 -0
  34. package/dist/api/generated/Supplier.d.ts +46 -0
  35. package/dist/api/generated/Supplier.d.ts.map +1 -0
  36. package/dist/api/generated/Supplier.js +87 -0
  37. package/dist/api/generated/Supplier.js.map +1 -0
  38. package/dist/api/generated/SupplierRoute.d.ts +101 -0
  39. package/dist/api/generated/SupplierRoute.d.ts.map +1 -0
  40. package/dist/api/generated/SupplierRoute.js +13 -0
  41. package/dist/api/generated/SupplierRoute.js.map +1 -0
  42. package/dist/api/generated/data-contracts.d.ts +277 -0
  43. package/dist/api/generated/data-contracts.d.ts.map +1 -0
  44. package/dist/api/generated/data-contracts.js +26 -0
  45. package/dist/api/generated/data-contracts.js.map +1 -0
  46. package/dist/api/generated/http-client.d.ts +61 -0
  47. package/dist/api/generated/http-client.d.ts.map +1 -0
  48. package/dist/api/generated/http-client.js +171 -0
  49. package/dist/api/generated/http-client.js.map +1 -0
  50. package/dist/api/index.d.ts +8 -0
  51. package/dist/api/index.d.ts.map +1 -0
  52. package/dist/api/index.js +8 -0
  53. package/dist/api/index.js.map +1 -0
  54. package/dist/api/methods/Import.api.d.ts +6 -0
  55. package/dist/api/methods/Import.api.d.ts.map +1 -0
  56. package/dist/api/methods/Import.api.js +27 -0
  57. package/dist/api/methods/Import.api.js.map +1 -0
  58. package/dist/api/methods/Order.api.d.ts +29 -0
  59. package/dist/api/methods/Order.api.d.ts.map +1 -0
  60. package/dist/api/methods/Order.api.js +52 -0
  61. package/dist/api/methods/Order.api.js.map +1 -0
  62. package/dist/api/methods/Product.api.d.ts +39 -0
  63. package/dist/api/methods/Product.api.d.ts.map +1 -0
  64. package/dist/api/methods/Product.api.js +69 -0
  65. package/dist/api/methods/Product.api.js.map +1 -0
  66. package/dist/api/methods/Report.api.d.ts +6 -0
  67. package/dist/api/methods/Report.api.d.ts.map +1 -0
  68. package/dist/api/methods/Report.api.js +19 -0
  69. package/dist/api/methods/Report.api.js.map +1 -0
  70. package/dist/api/methods/Supplier.api.d.ts +35 -0
  71. package/dist/api/methods/Supplier.api.d.ts.map +1 -0
  72. package/dist/api/methods/Supplier.api.js +63 -0
  73. package/dist/api/methods/Supplier.api.js.map +1 -0
  74. package/dist/index.cjs +47 -551
  75. package/dist/index.d.cts +108 -18
  76. package/dist/index.d.ts +108 -18
  77. package/dist/index.d.ts.map +1 -0
  78. package/dist/index.js +46 -551
  79. package/dist/index.js.map +1 -0
  80. package/dist/interfaces/ApiResult.d.ts +17 -0
  81. package/dist/interfaces/ApiResult.d.ts.map +1 -0
  82. package/dist/interfaces/ApiResult.js +2 -0
  83. package/dist/interfaces/ApiResult.js.map +1 -0
  84. package/dist/interfaces/Filter.d.ts +31 -0
  85. package/dist/interfaces/Filter.d.ts.map +1 -0
  86. package/dist/interfaces/Filter.js +2 -0
  87. package/dist/interfaces/Filter.js.map +1 -0
  88. package/dist/interfaces/SortType.d.ts +7 -0
  89. package/dist/interfaces/SortType.d.ts.map +1 -0
  90. package/dist/interfaces/SortType.js +2 -0
  91. package/dist/interfaces/SortType.js.map +1 -0
  92. package/dist/types/ApiCallOptions.d.ts +9 -0
  93. package/dist/types/ApiCallOptions.d.ts.map +1 -0
  94. package/dist/types/ApiCallOptions.js +2 -0
  95. package/dist/types/ApiCallOptions.js.map +1 -0
  96. package/dist/types/ApiMethodTypes.d.ts +24 -0
  97. package/dist/types/ApiMethodTypes.d.ts.map +1 -0
  98. package/dist/types/ApiMethodTypes.js +2 -0
  99. package/dist/types/ApiMethodTypes.js.map +1 -0
  100. package/dist/types/HttpResponse.d.ts +16 -0
  101. package/dist/types/HttpResponse.d.ts.map +1 -0
  102. package/dist/types/HttpResponse.js +2 -0
  103. package/dist/types/HttpResponse.js.map +1 -0
  104. package/dist/utils/SortTypeFromSortDirection.d.ts +22 -0
  105. package/dist/utils/SortTypeFromSortDirection.d.ts.map +1 -0
  106. package/dist/utils/SortTypeFromSortDirection.js +45 -0
  107. package/dist/utils/SortTypeFromSortDirection.js.map +1 -0
  108. package/dist/utils/buildQuery.d.ts +11 -0
  109. package/dist/utils/buildQuery.d.ts.map +1 -0
  110. package/dist/utils/buildQuery.js +94 -0
  111. package/dist/utils/buildQuery.js.map +1 -0
  112. package/dist/utils/extractArgsCallbacksAndParams.d.ts +22 -0
  113. package/dist/utils/extractArgsCallbacksAndParams.d.ts.map +1 -0
  114. package/dist/utils/extractArgsCallbacksAndParams.js +44 -0
  115. package/dist/utils/extractArgsCallbacksAndParams.js.map +1 -0
  116. package/dist/utils/extractArgsToastsAndParams.d.ts +18 -0
  117. package/dist/utils/extractArgsToastsAndParams.d.ts.map +1 -0
  118. package/dist/utils/extractArgsToastsAndParams.js +40 -0
  119. package/dist/utils/extractArgsToastsAndParams.js.map +1 -0
  120. package/dist/utils/handleApiResponse.d.ts +9 -0
  121. package/dist/utils/handleApiResponse.d.ts.map +1 -0
  122. package/dist/utils/handleApiResponse.js +49 -0
  123. package/dist/utils/handleApiResponse.js.map +1 -0
  124. package/dist/utils/toFormData.d.ts +8 -0
  125. package/dist/utils/toFormData.d.ts.map +1 -0
  126. package/dist/utils/toFormData.js +68 -0
  127. package/dist/utils/toFormData.js.map +1 -0
  128. package/package.json +5 -3
  129. package/scripts/generate-api-minimal.mjs +263 -25
package/README.md CHANGED
@@ -1,167 +1,314 @@
1
- # typedapi-client-helpers
2
-
3
- Reusable TypeScript helpers for generated typed OpenAPI clients.
4
-
5
- ## What this package includes
6
-
7
- * `typedapi-generate` CLI command
8
- * OpenAPI TypeScript client generation
9
- * Typed API wrapper methods
10
- * Typed query and pagination helpers
11
- * `ApiResult<T>` response wrapper
12
- * Toast helpers using `react-toastify`
13
- * `TypedApiToastProvider`
14
- * `buildQuery` helper for filters, paging, and sorting
15
- * `toFormData` helper for file uploads
16
- * Unauthorized handling for `401` responses
17
- * Sort direction conversion helpers
18
-
19
- ## Installation
20
-
21
- ```bash
22
- npm install typedapi-client-helpers
23
- ```
24
-
25
- This package expects React to already be installed:
26
-
27
- ```bash
28
- npm install react react-dom react-toastify
29
- ```
30
-
31
- ## Generate API files
32
-
33
- Add a script to your project:
34
-
35
- ```json
36
- {
37
- "scripts": {
38
- "generate:api": "typedapi-generate"
39
- }
40
- }
41
- ```
42
-
43
- Run:
44
-
45
- ```bash
46
- npm run generate:api
47
- ```
48
-
49
- By default, the generator reads Swagger from:
50
-
51
- ```text
52
- https://localhost:7000/swagger/v1/swagger.json
53
- ```
54
-
55
- and writes generated files to:
56
-
57
- ```text
58
- src/api
59
- ```
60
-
61
- ## Configuration
62
-
63
- Configure the generator in your `package.json`:
64
-
65
- ```json
66
- {
67
- "config": {
68
- "swaggerUrl": "https://localhost:7000/swagger/v1/swagger.json",
69
- "swaggerFile": "./swagger.json",
70
- "apiOutput": "src/api",
71
- "typedApiUseTypeOnlyImports": true,
72
- "typedApiUseFilterFormValues": false
73
- }
74
- }
75
- ```
76
-
77
- ### Available Settings
78
-
79
- | Setting | Description | Default |
80
- | ----------------------------- | ---------------------------------------------------------------- | ------------------------------------------------ |
81
- | `swaggerUrl` | URL to the Swagger/OpenAPI document | `https://localhost:7000/swagger/v1/swagger.json` |
82
- | `swaggerFile` | Local Swagger/OpenAPI file. Overrides `swaggerUrl` when provided | Not set |
83
- | `apiOutput` | Output directory for generated files | `src/api` |
84
- | `typedApiUseTypeOnlyImports` | Uses `import type` statements when possible | `false` |
85
- | `typedApiUseFilterFormValues` | Generates pagination methods using `FilterFormValues[]` | `false` |
86
-
87
- ### Environment Variables
88
-
89
- ```bash
90
- SWAGGER_URL=https://localhost:7000/swagger/v1/swagger.json npm run generate:api
91
- SWAGGER_FILE=./swagger.json npm run generate:api
92
- API_OUTPUT=src/api npm run generate:api
93
- TYPED_API_USE_TYPE_ONLY_IMPORTS=true npm run generate:api
94
- TYPED_API_USE_FILTER_FORM_VALUES=true npm run generate:api
95
- ```
96
-
97
- ## Usage
98
-
99
- Import generated API functions:
100
-
101
- ```ts
102
- import { getProducts } from "./api";
103
-
104
- const result = await getProducts();
105
-
106
- if (result.ok) {
107
- console.log(result.response);
108
- }
109
- ```
110
-
111
- ### Toast Notifications
112
-
113
- ```ts
114
- await createProduct(product, {
115
- toastSuccess: {
116
- title: "Saved",
117
- message: "Product created successfully."
118
- },
119
- toastError: {
120
- title: "Error",
121
- message: "Unable to create product."
122
- }
123
- });
124
- ```
125
-
126
- Add the provider once in your application:
127
-
128
- ```tsx
129
- import { TypedApiToastProvider } from "typedapi-client-helpers";
130
-
131
- function App() {
132
- return (
133
- <>
134
- <TypedApiToastProvider />
135
- {/* application */}
136
- </>
137
- );
138
- }
139
- ```
140
-
141
- ### File Uploads
142
-
143
- ```ts
144
- import { toFormData } from "typedapi-client-helpers";
145
-
146
- const formData = toFormData({
147
- file,
148
- description: "Import file"
149
- });
150
- ```
151
-
152
- ## Recommended Project Setup
153
-
154
- ```text
155
- src/
156
- ├── api/
157
- │ ├── clients/
158
- │ ├── models/
159
- │ └── index.ts
160
- ├── pages/
161
- ├── components/
162
- └── services/
163
- ```
164
-
165
- ## Notes
166
-
167
- Generated files should not be manually modified. Regenerate them whenever the backend OpenAPI specification changes.
1
+ # typedapi-client-helpers
2
+
3
+ `typedapi-client-helpers` generates a typed TypeScript API client from an OpenAPI/Swagger document and adds reusable helper types and functions for API results, callbacks, filtering, sorting, request parameters, and multipart uploads.
4
+
5
+ The package is meant for frontend projects that want a generated API client while still keeping the generated files inside their own source tree.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install typedapi-client-helpers
11
+ ```
12
+
13
+ ## Basic usage
14
+
15
+ Add a generator script to your project:
16
+
17
+ ```json
18
+ {
19
+ "scripts": {
20
+ "generate:api": "typedapi-generate"
21
+ }
22
+ }
23
+ ```
24
+
25
+ Run the generator:
26
+
27
+ ```bash
28
+ npm run generate:api
29
+ ```
30
+
31
+ By default the generator reads the Swagger document from `https://localhost:7000/swagger/v1/swagger.json` and writes the generated API client to `src/api`.
32
+
33
+ ## Configuration
34
+
35
+ Configuration can be supplied in the `config` section of your `package.json`, with environment variables, or with npm command-line arguments.
36
+
37
+ ### Package configuration
38
+
39
+ ```json
40
+ {
41
+ "config": {
42
+ "swaggerUrl": "https://localhost:7000/swagger/v1/swagger.json",
43
+ "swaggerFile": "swagger/openapi.json",
44
+ "apiOutput": "src/api",
45
+ "typedApiUseTypeOnlyImports": true,
46
+ "typedApiUseFilterFormValues": false,
47
+ "typedApiDefaultFunctionsPath": "../../defaultApiFunctions",
48
+ "typedApiDefaultSuccessHandler": "handleGoodResult",
49
+ "typedApiDefaultErrorHandler": "handleErrors"
50
+ }
51
+ }
52
+ ```
53
+
54
+ `swaggerFile` takes precedence over `swaggerUrl` when both are configured.
55
+
56
+ ### Configuration options
57
+
58
+ | Option | Default | Description |
59
+ | ------------------------------- | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ |
60
+ | `swaggerUrl` | `https://localhost:7000/swagger/v1/swagger.json` | URL of the OpenAPI/Swagger document. |
61
+ | `swaggerFile` | none | Local path to an OpenAPI/Swagger document. When set, this is used instead of `swaggerUrl`. |
62
+ | `apiOutput` | `src/api` | Directory where the generated API files are written. |
63
+ | `typedApiUseTypeOnlyImports` | `false` | Generates `import type` statements for imports that are only used as types. |
64
+ | `typedApiUseFilterFormValues` | `false` | Generates paginated methods that accept `FilterFormValues[]`, page values, and sort values instead of a prebuilt query object. |
65
+ | `typedApiDefaultFunctionsPath` | `../../defaultApiFunctions` | Import path used by generated method files for shared success and error handlers. |
66
+ | `typedApiDefaultSuccessHandler` | `handleGoodResult` | Name of the default success handler function imported into generated methods. |
67
+ | `typedApiDefaultErrorHandler` | `handleErrors` | Name of the default error handler function imported into generated methods. |
68
+
69
+ ### Environment variables
70
+
71
+ | Environment variable | Description |
72
+ | ---------------------------------- | --------------------------------------------------------------- |
73
+ | `SWAGGER_URL` | URL of the OpenAPI/Swagger document. |
74
+ | `SWAGGER_FILE` | Local path to an OpenAPI/Swagger document. |
75
+ | `API_OUTPUT` | Directory where generated API files are written. |
76
+ | `TYPED_API_USE_TYPE_ONLY_IMPORTS` | Enables type-only imports when set to `true`. |
77
+ | `TYPED_API_USE_FILTER_FORM_VALUES` | Enables filter-form based paginated methods when set to `true`. |
78
+
79
+ Example:
80
+
81
+ ```bash
82
+ SWAGGER_URL=https://localhost:7000/swagger/v1/swagger.json npm run generate:api
83
+ ```
84
+
85
+ ### Command-line npm config
86
+
87
+ ```bash
88
+ npm run generate:api --swagger-url=https://localhost:7000/swagger/v1/swagger.json
89
+ npm run generate:api --swagger-file=swagger/openapi.json
90
+ npm run generate:api --api-output=src/api
91
+ ```
92
+
93
+ ## Generated structure
94
+
95
+ Running the generator creates a structure similar to this:
96
+
97
+ ```text
98
+ src/
99
+ └── api/
100
+ ├── generated/
101
+ │ ├── data-contracts.ts
102
+ │ ├── http-client.ts
103
+ │ ├── Product.ts
104
+ │ └── Supplier.ts
105
+ ├── methods/
106
+ │ ├── Product.api.ts
107
+ │ └── Supplier.api.ts
108
+ └── index.ts
109
+ ```
110
+
111
+ | Folder or file | Description |
112
+ | ------------------------ | --------------------------------------------------------------------------------------------------------------- |
113
+ | `generated/` | Raw client, models, route classes, and HTTP client generated by `swagger-typescript-api`. |
114
+ | `methods/` | Typed wrapper methods generated by this package. These call the raw generated client and return `ApiResult<T>`. |
115
+ | `index.ts` | Barrel file that exports generated contracts, HTTP client types, and wrapper methods. |
116
+ | `defaultApiFunctions.ts` | Optional shared success and error handlers created when the configured default handler file does not exist. |
117
+
118
+ ## Calling generated methods
119
+
120
+ Generated wrapper methods return `ApiResult<T>`.
121
+
122
+ ```ts
123
+ import { getSuppliers } from "./api";
124
+
125
+ const result = await getSuppliers({
126
+ pageNumber: 1,
127
+ pageSize: 25,
128
+ });
129
+
130
+ if (result.ok) {
131
+ console.log(result.response);
132
+ } else {
133
+ console.error(result.status, result.error);
134
+ }
135
+ ```
136
+
137
+ Checking `result.ok` narrows the result automatically.
138
+
139
+ ## Success and error callbacks
140
+
141
+ Callbacks receive the full result object, not just the raw response or error.
142
+
143
+ ```ts
144
+ import type { ApiErrorResult, ApiSuccessResult } from "typedapi-client-helpers";
145
+ import { getSuppliers, type SupplierListResponse } from "./api";
146
+
147
+ function onSuccess(result: ApiSuccessResult<SupplierListResponse>) {
148
+ console.log(result.status, result.response);
149
+ }
150
+
151
+ function onError(result: ApiErrorResult<SupplierListResponse>) {
152
+ console.error(result.status, result.error);
153
+ }
154
+
155
+ await getSuppliers({ pageNumber: 1, pageSize: 25 }, onSuccess, onError);
156
+ ```
157
+
158
+ The generated method still returns `ApiResult<T>` after callbacks run.
159
+
160
+ ## Custom request parameters
161
+
162
+ The final wrapper argument can contain request parameters supported by the generated HTTP client.
163
+
164
+ ```ts
165
+ const result = await getSuppliers(
166
+ { pageNumber: 1, pageSize: 25 },
167
+ undefined,
168
+ undefined,
169
+ {
170
+ headers: {
171
+ Authorization: `Bearer ${token}`,
172
+ },
173
+ },
174
+ );
175
+ ```
176
+
177
+ ## Filter-form generation
178
+
179
+ Set `typedApiUseFilterFormValues` to `true` to generate paginated methods that accept filter form values.
180
+
181
+ ```json
182
+ {
183
+ "config": {
184
+ "typedApiUseFilterFormValues": true
185
+ }
186
+ }
187
+ ```
188
+
189
+ Example:
190
+
191
+ ```ts
192
+ import type { FilterFormValues } from "typedapi-client-helpers";
193
+ import { getSuppliers, type GetSuppliersQuery } from "./api";
194
+
195
+ const filters: FilterFormValues<GetSuppliersQuery>[] = [
196
+ {
197
+ name: "Supplier name",
198
+ filterName: "name",
199
+ type: "string",
200
+ value: "Example",
201
+ isAList: false,
202
+ },
203
+ ];
204
+
205
+ const result = await getSuppliers(filters, 1, 25, "name", "Ascending");
206
+ ```
207
+
208
+ Empty filter values are ignored by `buildQuery`.
209
+
210
+ ## Multipart uploads
211
+
212
+ Generated methods that need multipart bodies can use `toFormData` internally. You can also use it directly:
213
+
214
+ ```ts
215
+ import { toFormData } from "typedapi-client-helpers";
216
+
217
+ const body = toFormData({
218
+ name: "Manual",
219
+ file,
220
+ tags: ["docs", "public"],
221
+ });
222
+ ```
223
+
224
+ Arrays are appended as repeated fields, files keep their filename, primitives become strings, and nested objects are JSON-stringified.
225
+
226
+ ## Public API reference
227
+
228
+ ### Result types
229
+
230
+ | Export | Description |
231
+ | --------------------- | --------------------------------------------------------------------------------------------------------------- |
232
+ | `ApiResult<T>` | Discriminated union returned by generated wrapper methods. Contains either a success branch or an error branch. |
233
+ | `ApiSuccessResult<T>` | Success-only branch of `ApiResult<T>`. Useful for success callbacks and helper functions. |
234
+ | `ApiErrorResult<T>` | Error-only branch of `ApiResult<T>`. Useful for error callbacks and helper functions. |
235
+
236
+ ### Filter and sort types
237
+
238
+ | Export | Description |
239
+ | -------------------------- | ---------------------------------------------------------------------------------------------------------------- |
240
+ | `FilterType` | Union of supported filter input types: number, date, string, timespan, boolean, boolean-button, and OptionValue. |
241
+ | `OptionValue` | Option object with a display `name` and submitted `value`. |
242
+ | `FilterFormValues<TQuery>` | Configuration object for one filter field mapped to a query property. |
243
+ | `SortType` | UI sort state: Default, Neutral, Ascending, or Descending. |
244
+ | `SortDirection` | Sort direction value accepted by generated query objects. Supports string or number values. |
245
+ | `ApiSortDirection` | Sort direction values accepted by the generated API: Default, Ascending, or Descending. |
246
+ | `sortTypes` | Constant list of all supported UI sort states. |
247
+
248
+ ### Callback and method types
249
+
250
+ | Export | Description |
251
+ | ------------------------------- | -------------------------------------------------------------------------------------------- |
252
+ | `ApiSuccessHandler<TResponse>` | Callback type for successful API results. |
253
+ | `ApiErrorHandler<TResponse>` | Callback type for failed API results. |
254
+ | `ApiMethodCallbacks<TResponse>` | Object shape for optional success callback, error callback, and request params. |
255
+ | `ExtractResponse<T>` | Extracts the response body type from a generated method promise. |
256
+ | `ExtractError<T>` | Extracts the error body type from a generated method promise. |
257
+ | `UnwrapArray<T>` | Extracts the item type from an array, otherwise keeps the original type. |
258
+ | `ExtractDataIfPaginated<T>` | Extracts the item type from a `{ data?: T[] }` paginated response. |
259
+ | `SortableKeys<T>` | Produces keys that can be used as sortable fields for a response type. |
260
+ | `WithoutRequestParams<T>` | Removes a trailing optional `RequestParams` argument from a generated method argument tuple. |
261
+
262
+ ### HTTP types
263
+
264
+ | Export | Description |
265
+ | ---------------------- | ------------------------------------------------------------------- |
266
+ | `HttpResponse<D, E>` | Extended fetch `Response` with typed `data` and `error` properties. |
267
+ | `RuntimeRequestParams` | Runtime request options object forwarded to generated API methods. |
268
+
269
+ ### Utility functions
270
+
271
+ | Export | Description |
272
+ | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
273
+ | `buildQuery<TQuery, TSortModel>()` | Builds a query object from filter form values, page values, and sort values. |
274
+ | `extractArgsCallbacksAndParams()` | Splits wrapper arguments into original API arguments, success callback, error callback, and request params. |
275
+ | `extractArgsToastsAndParams()` | Backwards-compatible alias-style extractor for wrapper arguments with success/error handlers and request params. |
276
+ | `handleApiResponse()` | Executes a generated API call and converts the response or thrown error into `ApiResult<T>`. |
277
+ | `getSortTypeFromSortDirection()` | Converts an API sort direction into a UI `SortType`. |
278
+ | `getSortDirectionFromSortType()` | Converts a UI `SortType` into an API sort direction. |
279
+ | `toFormData()` | Converts an object payload into `FormData`. |
280
+
281
+ ### Default callback functions
282
+
283
+ | Export | Description |
284
+ | ----------------------- | ------------------------------------------------------------------------------------------------------ |
285
+ | `handleGoodResult<T>()` | Default success handler template created for generated projects. It can be customized by the consumer. |
286
+ | `handleErrors<T>()` | Default error handler template created for generated projects. It can be customized by the consumer. |
287
+
288
+ ## Folder documentation
289
+
290
+ Additional README files are included in these folders:
291
+
292
+ | File | Description |
293
+ | -------------------------- | ----------------------------------------------------------- |
294
+ | `src/interfaces/README.md` | Documents exported interfaces and result/filter/sort types. |
295
+ | `src/types/README.md` | Documents helper types used by generated wrapper methods. |
296
+ | `src/utils/README.md` | Documents runtime helper functions. |
297
+ | `scripts/README.md` | Documents the API generator script. |
298
+ | `bin/README.md` | Documents the command-line entry point. |
299
+
300
+ ## Build the package
301
+
302
+ ```bash
303
+ npm run build
304
+ ```
305
+
306
+ ## Generate an API client while developing this package
307
+
308
+ ```bash
309
+ npm run generate:api
310
+ ```
311
+
312
+ ## Notes
313
+
314
+ Generated files inside `src/api` and `dist/api` depend on the Swagger document used during generation. Their exact method names, model names, and route files will change when the OpenAPI document changes.
@@ -0,0 +1,22 @@
1
+ import { ImportResult, UploadProductFilePayload, UploadSupplierFilePayload } from "./data-contracts";
2
+ import { HttpClient } from "./http-client";
3
+ import { RequestParams } from "./http-client";
4
+ export declare class Import<SecurityDataType = unknown> extends HttpClient<SecurityDataType> {
5
+ /**
6
+ * No description
7
+ *
8
+ * @tags Import
9
+ * @name UploadProductFile
10
+ * @request POST:/api/import/products
11
+ */
12
+ uploadProductFile: (data: UploadProductFilePayload, params?: RequestParams) => Promise<import("./http-client").HttpResponse<ImportResult, any>>;
13
+ /**
14
+ * No description
15
+ *
16
+ * @tags Import
17
+ * @name UploadSupplierFile
18
+ * @request POST:/api/import/suppliers
19
+ */
20
+ uploadSupplierFile: (data: UploadSupplierFilePayload, params?: RequestParams) => Promise<import("./http-client").HttpResponse<ImportResult, any>>;
21
+ }
22
+ //# sourceMappingURL=Import.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Import.d.ts","sourceRoot":"","sources":["../../../src/api/generated/Import.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,YAAY,EAAE,wBAAwB,EAAE,yBAAyB,EAAG,MAAM,kBAAkB,CAAC;AACtG,OAAO,EAAe,UAAU,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,qBAAa,MAAM,CACjB,gBAAgB,GAAG,OAAO,CAC1B,SAAQ,UAAU,CAAC,gBAAgB,CAAC;IACpC;;;;;;OAMG;IACH,iBAAiB,GACf,MAAM,wBAAwB,EAC9B,SAAQ,aAAkB,sEASvB;IACL;;;;;;OAMG;IACH,kBAAkB,GAChB,MAAM,yBAAyB,EAC/B,SAAQ,aAAkB,sEASvB;CACN"}
@@ -0,0 +1,48 @@
1
+ /* eslint-disable */
2
+ /* tslint:disable */
3
+ // @ts-nocheck
4
+ /*
5
+ * ---------------------------------------------------------------
6
+ * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
7
+ * ## ##
8
+ * ## AUTHOR: acacode ##
9
+ * ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
10
+ * ---------------------------------------------------------------
11
+ */
12
+ import { ContentType, HttpClient } from "./http-client";
13
+ export class Import extends HttpClient {
14
+ constructor() {
15
+ super(...arguments);
16
+ /**
17
+ * No description
18
+ *
19
+ * @tags Import
20
+ * @name UploadProductFile
21
+ * @request POST:/api/import/products
22
+ */
23
+ this.uploadProductFile = (data, params = {}) => this.request({
24
+ path: `/api/import/products`,
25
+ method: "POST",
26
+ body: data,
27
+ type: ContentType.FormData,
28
+ format: "json",
29
+ ...params,
30
+ });
31
+ /**
32
+ * No description
33
+ *
34
+ * @tags Import
35
+ * @name UploadSupplierFile
36
+ * @request POST:/api/import/suppliers
37
+ */
38
+ this.uploadSupplierFile = (data, params = {}) => this.request({
39
+ path: `/api/import/suppliers`,
40
+ method: "POST",
41
+ body: data,
42
+ type: ContentType.FormData,
43
+ format: "json",
44
+ ...params,
45
+ });
46
+ }
47
+ }
48
+ //# sourceMappingURL=Import.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Import.js","sourceRoot":"","sources":["../../../src/api/generated/Import.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,oBAAoB;AACpB,cAAc;AACd;;;;;;;GAOG;AAGH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGxD,MAAM,OAAO,MAEX,SAAQ,UAA4B;IAFtC;;QAGE;;;;;;WAMG;QACH,sBAAiB,GAAG,CAClB,IAA8B,EAC9B,SAAwB,EAAE,EAC1B,EAAE,CACF,IAAI,CAAC,OAAO,CAAoB;YAC9B,IAAI,EAAE,sBAAsB;YAC5B,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,WAAW,CAAC,QAAQ;YAC1B,MAAM,EAAE,MAAM;YACd,GAAG,MAAM;SACV,CAAC,CAAC;QACL;;;;;;WAMG;QACH,uBAAkB,GAAG,CACnB,IAA+B,EAC/B,SAAwB,EAAE,EAC1B,EAAE,CACF,IAAI,CAAC,OAAO,CAAoB;YAC9B,IAAI,EAAE,uBAAuB;YAC7B,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,WAAW,CAAC,QAAQ;YAC1B,MAAM,EAAE,MAAM;YACd,GAAG,MAAM;SACV,CAAC,CAAC;IACP,CAAC;CAAA"}
@@ -0,0 +1,30 @@
1
+ import { ImportResult, UploadProductFilePayload, UploadSupplierFilePayload } from "./data-contracts";
2
+ export declare namespace Import {
3
+ /**
4
+ * No description
5
+ * @tags Import
6
+ * @name UploadProductFile
7
+ * @request POST:/api/import/products
8
+ */
9
+ namespace UploadProductFile {
10
+ type RequestParams = {};
11
+ type RequestQuery = {};
12
+ type RequestBody = UploadProductFilePayload;
13
+ type RequestHeaders = {};
14
+ type ResponseBody = ImportResult;
15
+ }
16
+ /**
17
+ * No description
18
+ * @tags Import
19
+ * @name UploadSupplierFile
20
+ * @request POST:/api/import/suppliers
21
+ */
22
+ namespace UploadSupplierFile {
23
+ type RequestParams = {};
24
+ type RequestQuery = {};
25
+ type RequestBody = UploadSupplierFilePayload;
26
+ type RequestHeaders = {};
27
+ type ResponseBody = ImportResult;
28
+ }
29
+ }
30
+ //# sourceMappingURL=ImportRoute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImportRoute.d.ts","sourceRoot":"","sources":["../../../src/api/generated/ImportRoute.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,YAAY,EACZ,wBAAwB,EACxB,yBAAyB,EAC1B,MAAM,kBAAkB,CAAC;AAE1B,yBAAiB,MAAM,CAAC;IACtB;;;;;OAKG;IACH,UAAiB,iBAAiB,CAAC;QACjC,KAAY,aAAa,GAAG,EAAE,CAAC;QAC/B,KAAY,YAAY,GAAG,EAAE,CAAC;QAC9B,KAAY,WAAW,GAAG,wBAAwB,CAAC;QACnD,KAAY,cAAc,GAAG,EAAE,CAAC;QAChC,KAAY,YAAY,GAAG,YAAY,CAAC;KACzC;IAED;;;;;OAKG;IACH,UAAiB,kBAAkB,CAAC;QAClC,KAAY,aAAa,GAAG,EAAE,CAAC;QAC/B,KAAY,YAAY,GAAG,EAAE,CAAC;QAC9B,KAAY,WAAW,GAAG,yBAAyB,CAAC;QACpD,KAAY,cAAc,GAAG,EAAE,CAAC;QAChC,KAAY,YAAY,GAAG,YAAY,CAAC;KACzC;CACF"}
@@ -0,0 +1,13 @@
1
+ /* eslint-disable */
2
+ /* tslint:disable */
3
+ // @ts-nocheck
4
+ /*
5
+ * ---------------------------------------------------------------
6
+ * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
7
+ * ## ##
8
+ * ## AUTHOR: acacode ##
9
+ * ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
10
+ * ---------------------------------------------------------------
11
+ */
12
+ export {};
13
+ //# sourceMappingURL=ImportRoute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImportRoute.js","sourceRoot":"","sources":["../../../src/api/generated/ImportRoute.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,oBAAoB;AACpB,cAAc;AACd;;;;;;;GAOG"}
@@ -0,0 +1,38 @@
1
+ import { ApproveOrderParams, ApproveOrderRequest, CreateOrderRequest, GetOrderByIdParams, GetOrdersParams, OrderModel, OrderTableRowApiPaginationResponse } from "./data-contracts";
2
+ import { HttpClient } from "./http-client";
3
+ import { RequestParams } from "./http-client";
4
+ export declare class Order<SecurityDataType = unknown> extends HttpClient<SecurityDataType> {
5
+ /**
6
+ * No description
7
+ *
8
+ * @tags Order
9
+ * @name GetOrders
10
+ * @request GET:/api/orders
11
+ */
12
+ getOrders: (query?: GetOrdersParams, params?: RequestParams) => Promise<import("./http-client").HttpResponse<OrderTableRowApiPaginationResponse, any>>;
13
+ /**
14
+ * No description
15
+ *
16
+ * @tags Order
17
+ * @name CreateOrder
18
+ * @request POST:/api/orders
19
+ */
20
+ createOrder: (data: CreateOrderRequest, params?: RequestParams) => Promise<import("./http-client").HttpResponse<OrderModel, any>>;
21
+ /**
22
+ * No description
23
+ *
24
+ * @tags Order
25
+ * @name GetOrderById
26
+ * @request GET:/api/orders/{id}
27
+ */
28
+ getOrderById: ({ id }: GetOrderByIdParams, params?: RequestParams) => Promise<import("./http-client").HttpResponse<OrderModel, any>>;
29
+ /**
30
+ * No description
31
+ *
32
+ * @tags Order
33
+ * @name ApproveOrder
34
+ * @request PUT:/api/orders/{id}/approve
35
+ */
36
+ approveOrder: ({ id }: ApproveOrderParams, data: ApproveOrderRequest, params?: RequestParams) => Promise<import("./http-client").HttpResponse<OrderModel, any>>;
37
+ }
38
+ //# sourceMappingURL=Order.d.ts.map