@gewis/sudosos-client 0.0.0-develop.e05135a → 0.0.0-develop.e6519ec
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 +110 -0
- package/dist/api.d.ts +1230 -494
- package/dist/api.js +1063 -474
- package/dist/base.js +1 -1
- package/dist/common.d.ts +1 -1
- package/package.json +4 -4
package/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# @gewis/sudosos-client
|
|
2
|
+
|
|
3
|
+
Auto-generated TypeScript-Axios client for the SudoSOS API. Published on npm as [`@gewis/sudosos-client`](https://www.npmjs.com/package/@gewis/sudosos-client).
|
|
4
|
+
|
|
5
|
+
This package lives inside the [SudoSOS Backend](https://github.com/GEWIS/sudosos-backend/tree/develop/client) monorepo (`client/`) and is generated from the backend's Swagger/OpenAPI spec.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @gewis/sudosos-client
|
|
13
|
+
# or
|
|
14
|
+
yarn add @gewis/sudosos-client
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### Unauthorized API usage
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { BannersApi, Configuration } from '@gewis/sudosos-client';
|
|
25
|
+
|
|
26
|
+
const configuration = new Configuration({
|
|
27
|
+
basePath: 'https://sudosos.gewis.nl/api/v1',
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const bannersApi = new BannersApi(configuration);
|
|
31
|
+
bannersApi.getAllOpenBanners().then((res) => {
|
|
32
|
+
console.log(res.data);
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Authorized API usage
|
|
37
|
+
|
|
38
|
+
All API methods accept a single object parameter (named properties, no positional `undefined` placeholders needed).
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { AuthenticateApi, BalanceApi, Configuration } from '@gewis/sudosos-client';
|
|
42
|
+
|
|
43
|
+
const basePath = 'https://sudosos.gewis.nl/api/v1';
|
|
44
|
+
const configuration = new Configuration({ basePath });
|
|
45
|
+
|
|
46
|
+
// Authenticate with an API key
|
|
47
|
+
const { data } = await new AuthenticateApi(configuration).keyAuthentication({
|
|
48
|
+
keyAuthenticationRequest: { key: 'API_KEY', userId: 0 },
|
|
49
|
+
});
|
|
50
|
+
const jwtToken = data.token;
|
|
51
|
+
|
|
52
|
+
// Use the token for authenticated requests
|
|
53
|
+
const authedConfig = new Configuration({
|
|
54
|
+
basePath,
|
|
55
|
+
accessToken: () => jwtToken,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const balanceApi = new BalanceApi(authedConfig);
|
|
59
|
+
balanceApi.getBalances().then((res) => {
|
|
60
|
+
console.log(res.data);
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
For a more complete integration example, see [sudosos-frontend-common](https://github.com/GEWIS/sudosos-frontend-common).
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## How the client is generated
|
|
69
|
+
|
|
70
|
+
The client is generated from the OpenAPI spec that the backend emits at build time (`out/swagger.json`). The generator is [`openapi-generator-cli`](https://openapi-generator.tech/) using the `typescript-axios` template with `useSingleRequestParameter=true`.
|
|
71
|
+
|
|
72
|
+
### Prerequisites
|
|
73
|
+
|
|
74
|
+
- Node.js 22+
|
|
75
|
+
- Java runtime (required by `openapi-generator-cli`)
|
|
76
|
+
- The backend's Swagger output must exist at `../out/swagger.json` — run `npm run swagger` from the backend root first
|
|
77
|
+
|
|
78
|
+
### Common commands
|
|
79
|
+
|
|
80
|
+
| Command | Description |
|
|
81
|
+
|---|---|
|
|
82
|
+
| `npm run gen` | Generate TypeScript source from `../out/swagger.json` into `src/` |
|
|
83
|
+
| `npm run build` | Compile `src/` to `dist/` |
|
|
84
|
+
| `npm run genbuild` | Run `gen` then `build` (full regeneration) |
|
|
85
|
+
| `npm run clean` | Remove `src/` and `dist/` |
|
|
86
|
+
|
|
87
|
+
### Regenerating after a backend change
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# From the backend root — generate the OpenAPI spec first
|
|
91
|
+
npm run swagger # produces out/swagger.json
|
|
92
|
+
|
|
93
|
+
# Then regenerate the client
|
|
94
|
+
cd client
|
|
95
|
+
npm run genbuild
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Or use the one-shot helper from the backend root:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
npm run client:gen # runs npm run swagger, then cd client && npm install && npm run genbuild
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Contributing
|
|
107
|
+
|
|
108
|
+
This package is generated — do not edit files under `src/` by hand; they will be overwritten on the next `npm run gen`. To change the client's output, update the backend API and regenerate.
|
|
109
|
+
|
|
110
|
+
Issues and contributions go through the [SudoSOS Backend issue tracker](https://github.com/GEWIS/sudosos-backend/issues).
|