@tietokilta/pakuvaraus-client 0.0.0 → 0.1.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/README.md +66 -0
- package/index.d.ts +14 -0
- package/index.js +4 -0
- package/package.json +31 -8
- package/schema.d.ts +214 -0
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# @tietokilta/pakuvaraus-client
|
|
2
|
+
|
|
3
|
+
Typed `fetch` client for the pakuvaraus public API. The types in `schema.d.ts`
|
|
4
|
+
are generated by [openapi-typescript](https://openapi-ts.dev) from the API's
|
|
5
|
+
OpenAPI spec, which is generated from the Rust handlers with
|
|
6
|
+
[utoipa](https://github.com/juhaku/utoipa). Requests go through
|
|
7
|
+
[openapi-fetch](https://openapi-ts.dev/openapi-fetch/). Neither generated file
|
|
8
|
+
is committed.
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { createPakuvarausClient, type CreateReservation } from "@tietokilta/pakuvaraus-client";
|
|
12
|
+
|
|
13
|
+
const api = createPakuvarausClient({ baseUrl: "https://pakuvaraus.example" });
|
|
14
|
+
|
|
15
|
+
const { data, error } = await api.GET("/reservations");
|
|
16
|
+
|
|
17
|
+
const { response } = await api.POST("/reservations", {
|
|
18
|
+
body: reservation satisfies CreateReservation,
|
|
19
|
+
});
|
|
20
|
+
if (!response.ok) {
|
|
21
|
+
// handle the error
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Check `response.ok` after `POST /reservations`, not `error`. A successful
|
|
26
|
+
request has an empty body, so `data` and `error` are both `undefined`. They are
|
|
27
|
+
also both `undefined` for an empty-bodied failure, such as a 404 or 405 from a
|
|
28
|
+
wrong `baseUrl`.
|
|
29
|
+
|
|
30
|
+
`error` is typed per status: `ErrorResponse` (`{ error: string }`) for 409 and
|
|
31
|
+
500, and a plain-text string for 400, 413, 415 and 422 (axum's body
|
|
32
|
+
rejections).
|
|
33
|
+
|
|
34
|
+
Cancelling isn't part of this API. The confirmation email links to
|
|
35
|
+
pakuvaraus's own HTML cancel page.
|
|
36
|
+
|
|
37
|
+
## Building
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
nix build .#openapi-spec # result: the OpenAPI spec
|
|
41
|
+
nix build .#api-client # result/: the npm package, ready to publish
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`nix flake check` builds both, so a handler change that breaks the client's
|
|
45
|
+
types fails CI. The running server also serves the spec at `/openapi.json`.
|
|
46
|
+
|
|
47
|
+
To work on `index.js`/`index.d.ts` locally, in `nix develop`:
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
nix build .#openapi-spec -o client/openapi.json
|
|
51
|
+
cd client && pnpm install && pnpm run generate && pnpm run typecheck
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Releasing
|
|
55
|
+
|
|
56
|
+
On every push to `main`, after the Azure deploy succeeds, the `publish-client` job in
|
|
57
|
+
[`release.yml`](../.github/workflows/release.yml) builds `.#api-client`. When its
|
|
58
|
+
contents differ from the latest published version, it publishes the next
|
|
59
|
+
patch version with trusted publishing. It takes major and minor from
|
|
60
|
+
`version` in `package.json`, and ignores the patch there.
|
|
61
|
+
For a breaking API change, bump the minor version (or the major after 1.0) in
|
|
62
|
+
`package.json`, since `^0.1.0` only accepts new `0.1.x` patches. The npm
|
|
63
|
+
package's settings must list `release.yml` with environment `npm-publish` as a
|
|
64
|
+
trusted publisher that is allowed to run `npm publish`. That GitHub environment
|
|
65
|
+
must only allow the `main` branch. A run only publishes if its commit is still
|
|
66
|
+
the head of `main`, so rerunning an old run does nothing.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Client, ClientOptions } from "openapi-fetch";
|
|
2
|
+
import type { paths } from "./schema.js";
|
|
3
|
+
|
|
4
|
+
export type * from "./schema.js";
|
|
5
|
+
|
|
6
|
+
export type PakuvarausClient = Client<paths>;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Create a client for the pakuvaraus API. Pass `baseUrl`, the API origin
|
|
10
|
+
* such as `https://pakuvaraus.tietokilta.fi`, and optionally a custom `fetch`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createPakuvarausClient(
|
|
13
|
+
options?: ClientOptions,
|
|
14
|
+
): PakuvarausClient;
|
package/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,13 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tietokilta/pakuvaraus-client",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Typed fetch client for the pakuvaraus API, generated from its OpenAPI spec",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/Tietokilta/pakuvaraus.git",
|
|
8
|
+
"directory": "client"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./index.d.ts",
|
|
17
|
+
"default": "./index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"index.js",
|
|
22
|
+
"index.d.ts",
|
|
23
|
+
"schema.d.ts"
|
|
24
|
+
],
|
|
6
25
|
"scripts": {
|
|
7
|
-
"
|
|
26
|
+
"generate": "openapi-typescript openapi.json --root-types --root-types-no-schema-prefix --output schema.d.ts",
|
|
27
|
+
"typecheck": "tsc"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"openapi-fetch": "^0.17.0"
|
|
8
31
|
},
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"openapi-typescript": "7.13.0",
|
|
34
|
+
"typescript": "^5.9.3"
|
|
35
|
+
}
|
|
13
36
|
}
|
package/schema.d.ts
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was auto-generated by openapi-typescript.
|
|
3
|
+
* Do not make direct changes to the file.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface paths {
|
|
7
|
+
"/reservations": {
|
|
8
|
+
parameters: {
|
|
9
|
+
query?: never;
|
|
10
|
+
header?: never;
|
|
11
|
+
path?: never;
|
|
12
|
+
cookie?: never;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* List when the van is taken.
|
|
16
|
+
* @description Returns pending and approved reservations that overlap `[from, to)`,
|
|
17
|
+
* ordered by start time. Either bound may be left out. An empty or reversed
|
|
18
|
+
* range returns an empty list. Cancelled reservations and personal data are
|
|
19
|
+
* left out.
|
|
20
|
+
*/
|
|
21
|
+
get: operations["listReservations"];
|
|
22
|
+
put?: never;
|
|
23
|
+
/**
|
|
24
|
+
* Request a reservation.
|
|
25
|
+
* @description Generates the rental contract, emails it to the approver, and emails the
|
|
26
|
+
* requester a confirmation with a cancel link. The reservation stays pending
|
|
27
|
+
* until an admin approves it.
|
|
28
|
+
*/
|
|
29
|
+
post: operations["createReservation"];
|
|
30
|
+
delete?: never;
|
|
31
|
+
options?: never;
|
|
32
|
+
head?: never;
|
|
33
|
+
patch?: never;
|
|
34
|
+
trace?: never;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export type webhooks = Record<string, never>;
|
|
38
|
+
export interface components {
|
|
39
|
+
schemas: {
|
|
40
|
+
Address: string;
|
|
41
|
+
CreateReservation: {
|
|
42
|
+
/** Format: date-time */
|
|
43
|
+
end_time: string;
|
|
44
|
+
/** Format: date-time */
|
|
45
|
+
start_time: string;
|
|
46
|
+
} & {
|
|
47
|
+
address: components["schemas"]["Address"];
|
|
48
|
+
email: components["schemas"]["Email"];
|
|
49
|
+
full_name: components["schemas"]["FullName"];
|
|
50
|
+
/** @description Reserved for guild use rather than a member's personal use */
|
|
51
|
+
internal: boolean;
|
|
52
|
+
phone_number: components["schemas"]["Phone"];
|
|
53
|
+
used_outside_finland: boolean;
|
|
54
|
+
};
|
|
55
|
+
/** Format: email */
|
|
56
|
+
Email: string;
|
|
57
|
+
/** @description Body of every error response that the app itself produces. */
|
|
58
|
+
ErrorResponse: {
|
|
59
|
+
/** @description Human-readable description of the error */
|
|
60
|
+
error: string;
|
|
61
|
+
};
|
|
62
|
+
FullName: string;
|
|
63
|
+
/** @description Phone number; a number without a country code is read as Finnish */
|
|
64
|
+
Phone: string;
|
|
65
|
+
/** @description When the van is taken, without personal data. */
|
|
66
|
+
ReservationItem: {
|
|
67
|
+
/** @description Approved by an admin; otherwise the request is still pending */
|
|
68
|
+
approved: boolean;
|
|
69
|
+
/** Format: date-time */
|
|
70
|
+
end_time: string;
|
|
71
|
+
/**
|
|
72
|
+
* @description Reserved for guild use. A member's reservation can't overlap a guild
|
|
73
|
+
* one, but a guild reservation may overlap a member's.
|
|
74
|
+
*/
|
|
75
|
+
internal: boolean;
|
|
76
|
+
/** Format: date-time */
|
|
77
|
+
start_time: string;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
responses: never;
|
|
81
|
+
parameters: never;
|
|
82
|
+
requestBodies: never;
|
|
83
|
+
headers: never;
|
|
84
|
+
pathItems: never;
|
|
85
|
+
}
|
|
86
|
+
export type Address = components['schemas']['Address'];
|
|
87
|
+
export type CreateReservation = components['schemas']['CreateReservation'];
|
|
88
|
+
export type Email = components['schemas']['Email'];
|
|
89
|
+
export type ErrorResponse = components['schemas']['ErrorResponse'];
|
|
90
|
+
export type FullName = components['schemas']['FullName'];
|
|
91
|
+
export type Phone = components['schemas']['Phone'];
|
|
92
|
+
export type ReservationItem = components['schemas']['ReservationItem'];
|
|
93
|
+
export type $defs = Record<string, never>;
|
|
94
|
+
export interface operations {
|
|
95
|
+
listReservations: {
|
|
96
|
+
parameters: {
|
|
97
|
+
query?: {
|
|
98
|
+
/** @description Only reservations that end after this time */
|
|
99
|
+
from?: string;
|
|
100
|
+
/** @description Only reservations that start before this time */
|
|
101
|
+
to?: string;
|
|
102
|
+
};
|
|
103
|
+
header?: never;
|
|
104
|
+
path?: never;
|
|
105
|
+
cookie?: never;
|
|
106
|
+
};
|
|
107
|
+
requestBody?: never;
|
|
108
|
+
responses: {
|
|
109
|
+
/** @description Pending and approved reservations in the range */
|
|
110
|
+
200: {
|
|
111
|
+
headers: {
|
|
112
|
+
[name: string]: unknown;
|
|
113
|
+
};
|
|
114
|
+
content: {
|
|
115
|
+
"application/json": components["schemas"]["ReservationItem"][];
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
/** @description `from` or `to` is not an RFC 3339 timestamp */
|
|
119
|
+
400: {
|
|
120
|
+
headers: {
|
|
121
|
+
[name: string]: unknown;
|
|
122
|
+
};
|
|
123
|
+
content: {
|
|
124
|
+
"text/plain": string;
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
/** @description Internal server error */
|
|
128
|
+
500: {
|
|
129
|
+
headers: {
|
|
130
|
+
[name: string]: unknown;
|
|
131
|
+
};
|
|
132
|
+
content: {
|
|
133
|
+
"application/json": components["schemas"]["ErrorResponse"];
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
createReservation: {
|
|
139
|
+
parameters: {
|
|
140
|
+
query?: never;
|
|
141
|
+
header?: never;
|
|
142
|
+
path?: never;
|
|
143
|
+
cookie?: never;
|
|
144
|
+
};
|
|
145
|
+
requestBody: {
|
|
146
|
+
content: {
|
|
147
|
+
"application/json": components["schemas"]["CreateReservation"];
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
responses: {
|
|
151
|
+
/** @description Reservation requested. The response body is empty. */
|
|
152
|
+
200: {
|
|
153
|
+
headers: {
|
|
154
|
+
[name: string]: unknown;
|
|
155
|
+
};
|
|
156
|
+
content?: never;
|
|
157
|
+
};
|
|
158
|
+
/** @description The body is not valid JSON */
|
|
159
|
+
400: {
|
|
160
|
+
headers: {
|
|
161
|
+
[name: string]: unknown;
|
|
162
|
+
};
|
|
163
|
+
content: {
|
|
164
|
+
"text/plain": string;
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
/** @description The time overlaps another reservation */
|
|
168
|
+
409: {
|
|
169
|
+
headers: {
|
|
170
|
+
[name: string]: unknown;
|
|
171
|
+
};
|
|
172
|
+
content: {
|
|
173
|
+
"application/json": components["schemas"]["ErrorResponse"];
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
/** @description The body is larger than the server accepts */
|
|
177
|
+
413: {
|
|
178
|
+
headers: {
|
|
179
|
+
[name: string]: unknown;
|
|
180
|
+
};
|
|
181
|
+
content: {
|
|
182
|
+
"text/plain": string;
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
/** @description The `Content-Type` header is not `application/json` */
|
|
186
|
+
415: {
|
|
187
|
+
headers: {
|
|
188
|
+
[name: string]: unknown;
|
|
189
|
+
};
|
|
190
|
+
content: {
|
|
191
|
+
"text/plain": string;
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
/** @description A field is missing or invalid; the message names the problem */
|
|
195
|
+
422: {
|
|
196
|
+
headers: {
|
|
197
|
+
[name: string]: unknown;
|
|
198
|
+
};
|
|
199
|
+
content: {
|
|
200
|
+
"text/plain": string;
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
/** @description Internal server error */
|
|
204
|
+
500: {
|
|
205
|
+
headers: {
|
|
206
|
+
[name: string]: unknown;
|
|
207
|
+
};
|
|
208
|
+
content: {
|
|
209
|
+
"application/json": components["schemas"]["ErrorResponse"];
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
}
|