@gewis/sudosos-client 0.0.0-develop.e05135a → 0.0.0-develop.e57eec7
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 +116 -0
- package/dist/api.d.ts +2054 -799
- package/dist/api.js +1478 -389
- package/dist/base.d.ts +1 -1
- package/dist/base.js +2 -2
- package/dist/common.d.ts +2 -2
- package/dist/common.js +1 -1
- package/dist/configuration.d.ts +1 -1
- package/dist/configuration.js +1 -1
- package/dist/esm/api.d.ts +19918 -0
- package/dist/esm/api.js +16762 -0
- package/dist/esm/base.d.ts +66 -0
- package/dist/esm/base.js +59 -0
- package/dist/esm/common.d.ts +65 -0
- package/dist/esm/common.js +133 -0
- package/dist/esm/configuration.d.ts +91 -0
- package/dist/esm/configuration.js +39 -0
- package/dist/esm/index.d.ts +13 -0
- package/dist/esm/index.js +15 -0
- package/dist/esm/package.json +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +10 -9
package/README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
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 at `packages/sudosos-client/` in the [GEWIS/sudosos](https://github.com/GEWIS/sudosos)
|
|
6
|
+
monorepo and is generated from the backend's Swagger/OpenAPI spec. The frontend apps in this same repo
|
|
7
|
+
consume it directly as a `workspace:*` dependency, not via the npm-published version.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @gewis/sudosos-client
|
|
15
|
+
# or
|
|
16
|
+
yarn add @gewis/sudosos-client
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### Unauthorized API usage
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { BannersApi, Configuration } from '@gewis/sudosos-client';
|
|
27
|
+
|
|
28
|
+
const configuration = new Configuration({
|
|
29
|
+
basePath: 'https://sudosos.gewis.nl/api/v1',
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const bannersApi = new BannersApi(configuration);
|
|
33
|
+
bannersApi.getAllOpenBanners().then((res) => {
|
|
34
|
+
console.log(res.data);
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Authorized API usage
|
|
39
|
+
|
|
40
|
+
All API methods accept a single object parameter (named properties, no positional `undefined` placeholders needed).
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { AuthenticateApi, BalanceApi, Configuration } from '@gewis/sudosos-client';
|
|
44
|
+
|
|
45
|
+
const basePath = 'https://sudosos.gewis.nl/api/v1';
|
|
46
|
+
const configuration = new Configuration({ basePath });
|
|
47
|
+
|
|
48
|
+
// Authenticate with an API key
|
|
49
|
+
const { data } = await new AuthenticateApi(configuration).keyAuthentication({
|
|
50
|
+
keyAuthenticationRequest: { key: 'API_KEY', userId: 0 },
|
|
51
|
+
});
|
|
52
|
+
const jwtToken = data.token;
|
|
53
|
+
|
|
54
|
+
// Use the token for authenticated requests
|
|
55
|
+
const authedConfig = new Configuration({
|
|
56
|
+
basePath,
|
|
57
|
+
accessToken: () => jwtToken,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const balanceApi = new BalanceApi(authedConfig);
|
|
61
|
+
balanceApi.getBalances().then((res) => {
|
|
62
|
+
console.log(res.data);
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
For a more complete integration example, see [`frontend/lib/common`](../../frontend/lib/common) in this repo.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## How the client is generated
|
|
71
|
+
|
|
72
|
+
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`.
|
|
73
|
+
|
|
74
|
+
### Prerequisites
|
|
75
|
+
|
|
76
|
+
- Node.js 22+
|
|
77
|
+
- Java 11+ runtime (required by `openapi-generator-cli`) — only needed to *regenerate* the client;
|
|
78
|
+
the generated `src/` is committed, so day-to-day frontend work never needs Java.
|
|
79
|
+
- The backend's Swagger output must exist at `../../backend/out/swagger.json` — run `pnpm backend:swagger`
|
|
80
|
+
from the repo root first (or `pnpm swagger` from `backend/`).
|
|
81
|
+
|
|
82
|
+
### Common commands
|
|
83
|
+
|
|
84
|
+
Run from this directory (`packages/sudosos-client/`) once the monorepo workspace is installed, or via
|
|
85
|
+
`pnpm --filter @gewis/sudosos-client <script>` from anywhere in the repo:
|
|
86
|
+
|
|
87
|
+
| Command | Description |
|
|
88
|
+
|---|---|
|
|
89
|
+
| `pnpm gen` | Generate TypeScript source from `../../backend/out/swagger.json` into `src/` |
|
|
90
|
+
| `pnpm build` | Compile `src/` to `dist/` (CJS) and `dist/esm/` (ESM, for bundler consumers) |
|
|
91
|
+
| `pnpm genbuild` | Run `gen` then `build` (full regeneration) |
|
|
92
|
+
| `pnpm clean` | Remove `src/` and `dist/` |
|
|
93
|
+
|
|
94
|
+
### Regenerating after a backend change
|
|
95
|
+
|
|
96
|
+
One-shot, from the repo root:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
pnpm generate:client # runs backend swagger, then this package's genbuild
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Or step by step:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
pnpm backend:swagger # produces backend/out/swagger.json
|
|
106
|
+
pnpm --filter @gewis/sudosos-client run genbuild # regenerate + rebuild the client
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Contributing
|
|
112
|
+
|
|
113
|
+
This package is generated — do not edit files under `src/` by hand; they will be overwritten on the next
|
|
114
|
+
`pnpm gen`. To change the client's output, update the backend API and regenerate.
|
|
115
|
+
|
|
116
|
+
Issues and contributions go through the [GEWIS/sudosos issue tracker](https://github.com/GEWIS/sudosos/issues).
|