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.
- package/README.md +314 -167
- package/dist/api/generated/Import.d.ts +22 -0
- package/dist/api/generated/Import.d.ts.map +1 -0
- package/dist/api/generated/Import.js +48 -0
- package/dist/api/generated/Import.js.map +1 -0
- package/dist/api/generated/ImportRoute.d.ts +30 -0
- package/dist/api/generated/ImportRoute.d.ts.map +1 -0
- package/dist/api/generated/ImportRoute.js +13 -0
- package/dist/api/generated/ImportRoute.js.map +1 -0
- package/dist/api/generated/Order.d.ts +38 -0
- package/dist/api/generated/Order.d.ts.map +1 -0
- package/dist/api/generated/Order.js +75 -0
- package/dist/api/generated/Order.js.map +1 -0
- package/dist/api/generated/OrderRoute.d.ts +83 -0
- package/dist/api/generated/OrderRoute.d.ts.map +1 -0
- package/dist/api/generated/OrderRoute.js +13 -0
- package/dist/api/generated/OrderRoute.js.map +1 -0
- package/dist/api/generated/Product.d.ts +62 -0
- package/dist/api/generated/Product.d.ts.map +1 -0
- package/dist/api/generated/Product.js +114 -0
- package/dist/api/generated/Product.js.map +1 -0
- package/dist/api/generated/ProductRoute.d.ts +140 -0
- package/dist/api/generated/ProductRoute.d.ts.map +1 -0
- package/dist/api/generated/ProductRoute.js +13 -0
- package/dist/api/generated/ProductRoute.js.map +1 -0
- package/dist/api/generated/Report.d.ts +14 -0
- package/dist/api/generated/Report.d.ts.map +1 -0
- package/dist/api/generated/Report.js +32 -0
- package/dist/api/generated/Report.js.map +1 -0
- package/dist/api/generated/ReportRoute.d.ts +23 -0
- package/dist/api/generated/ReportRoute.d.ts.map +1 -0
- package/dist/api/generated/ReportRoute.js +13 -0
- package/dist/api/generated/ReportRoute.js.map +1 -0
- package/dist/api/generated/Supplier.d.ts +46 -0
- package/dist/api/generated/Supplier.d.ts.map +1 -0
- package/dist/api/generated/Supplier.js +87 -0
- package/dist/api/generated/Supplier.js.map +1 -0
- package/dist/api/generated/SupplierRoute.d.ts +101 -0
- package/dist/api/generated/SupplierRoute.d.ts.map +1 -0
- package/dist/api/generated/SupplierRoute.js +13 -0
- package/dist/api/generated/SupplierRoute.js.map +1 -0
- package/dist/api/generated/data-contracts.d.ts +277 -0
- package/dist/api/generated/data-contracts.d.ts.map +1 -0
- package/dist/api/generated/data-contracts.js +26 -0
- package/dist/api/generated/data-contracts.js.map +1 -0
- package/dist/api/generated/http-client.d.ts +61 -0
- package/dist/api/generated/http-client.d.ts.map +1 -0
- package/dist/api/generated/http-client.js +171 -0
- package/dist/api/generated/http-client.js.map +1 -0
- package/dist/api/index.d.ts +8 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +8 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/methods/Import.api.d.ts +6 -0
- package/dist/api/methods/Import.api.d.ts.map +1 -0
- package/dist/api/methods/Import.api.js +27 -0
- package/dist/api/methods/Import.api.js.map +1 -0
- package/dist/api/methods/Order.api.d.ts +29 -0
- package/dist/api/methods/Order.api.d.ts.map +1 -0
- package/dist/api/methods/Order.api.js +52 -0
- package/dist/api/methods/Order.api.js.map +1 -0
- package/dist/api/methods/Product.api.d.ts +39 -0
- package/dist/api/methods/Product.api.d.ts.map +1 -0
- package/dist/api/methods/Product.api.js +69 -0
- package/dist/api/methods/Product.api.js.map +1 -0
- package/dist/api/methods/Report.api.d.ts +6 -0
- package/dist/api/methods/Report.api.d.ts.map +1 -0
- package/dist/api/methods/Report.api.js +19 -0
- package/dist/api/methods/Report.api.js.map +1 -0
- package/dist/api/methods/Supplier.api.d.ts +35 -0
- package/dist/api/methods/Supplier.api.d.ts.map +1 -0
- package/dist/api/methods/Supplier.api.js +63 -0
- package/dist/api/methods/Supplier.api.js.map +1 -0
- package/dist/index.cjs +47 -551
- package/dist/index.d.cts +108 -18
- package/dist/index.d.ts +108 -18
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -551
- package/dist/index.js.map +1 -0
- package/dist/interfaces/ApiResult.d.ts +17 -0
- package/dist/interfaces/ApiResult.d.ts.map +1 -0
- package/dist/interfaces/ApiResult.js +2 -0
- package/dist/interfaces/ApiResult.js.map +1 -0
- package/dist/interfaces/Filter.d.ts +31 -0
- package/dist/interfaces/Filter.d.ts.map +1 -0
- package/dist/interfaces/Filter.js +2 -0
- package/dist/interfaces/Filter.js.map +1 -0
- package/dist/interfaces/SortType.d.ts +7 -0
- package/dist/interfaces/SortType.d.ts.map +1 -0
- package/dist/interfaces/SortType.js +2 -0
- package/dist/interfaces/SortType.js.map +1 -0
- package/dist/types/ApiCallOptions.d.ts +9 -0
- package/dist/types/ApiCallOptions.d.ts.map +1 -0
- package/dist/types/ApiCallOptions.js +2 -0
- package/dist/types/ApiCallOptions.js.map +1 -0
- package/dist/types/ApiMethodTypes.d.ts +24 -0
- package/dist/types/ApiMethodTypes.d.ts.map +1 -0
- package/dist/types/ApiMethodTypes.js +2 -0
- package/dist/types/ApiMethodTypes.js.map +1 -0
- package/dist/types/HttpResponse.d.ts +16 -0
- package/dist/types/HttpResponse.d.ts.map +1 -0
- package/dist/types/HttpResponse.js +2 -0
- package/dist/types/HttpResponse.js.map +1 -0
- package/dist/utils/SortTypeFromSortDirection.d.ts +22 -0
- package/dist/utils/SortTypeFromSortDirection.d.ts.map +1 -0
- package/dist/utils/SortTypeFromSortDirection.js +45 -0
- package/dist/utils/SortTypeFromSortDirection.js.map +1 -0
- package/dist/utils/buildQuery.d.ts +11 -0
- package/dist/utils/buildQuery.d.ts.map +1 -0
- package/dist/utils/buildQuery.js +94 -0
- package/dist/utils/buildQuery.js.map +1 -0
- package/dist/utils/extractArgsCallbacksAndParams.d.ts +22 -0
- package/dist/utils/extractArgsCallbacksAndParams.d.ts.map +1 -0
- package/dist/utils/extractArgsCallbacksAndParams.js +44 -0
- package/dist/utils/extractArgsCallbacksAndParams.js.map +1 -0
- package/dist/utils/extractArgsToastsAndParams.d.ts +18 -0
- package/dist/utils/extractArgsToastsAndParams.d.ts.map +1 -0
- package/dist/utils/extractArgsToastsAndParams.js +40 -0
- package/dist/utils/extractArgsToastsAndParams.js.map +1 -0
- package/dist/utils/handleApiResponse.d.ts +9 -0
- package/dist/utils/handleApiResponse.d.ts.map +1 -0
- package/dist/utils/handleApiResponse.js +49 -0
- package/dist/utils/handleApiResponse.js.map +1 -0
- package/dist/utils/toFormData.d.ts +8 -0
- package/dist/utils/toFormData.d.ts.map +1 -0
- package/dist/utils/toFormData.js +68 -0
- package/dist/utils/toFormData.js.map +1 -0
- package/package.json +5 -3
- package/scripts/generate-api-minimal.mjs +263 -25
package/README.md
CHANGED
|
@@ -1,167 +1,314 @@
|
|
|
1
|
-
# typedapi-client-helpers
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
npm
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
```ts
|
|
144
|
-
import {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|