@myronsi/messenger-api 2.0.0-alpha.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/CHANGELOG.md +11 -0
- package/README.md +58 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1 -0
- package/dist/openapi.yaml +2334 -0
- package/dist/schema.d.ts +3889 -0
- package/dist/ws-docs.json +428 -0
- package/dist/ws-events.d.ts +526 -0
- package/dist/ws-events.schema.json +2739 -0
- package/package.json +54 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# API contract changelog
|
|
2
|
+
|
|
3
|
+
Contract changes only. The backend changelog is `CHANGELOG.md` in the repository root. Rules: `docs/api-compatibility.md`.
|
|
4
|
+
|
|
5
|
+
## 2.0.0-alpha.1
|
|
6
|
+
|
|
7
|
+
First draft of API contract v2 for the Go backend (`/api/v2`), published as `@myronsi/messenger-api@2.0.0-alpha.1`:
|
|
8
|
+
|
|
9
|
+
- OpenAPI 3.1 document for all REST endpoints of the parity list.
|
|
10
|
+
- WebSocket protocol: one connection per user with a ticket, an event envelope, `client_temp_id` acknowledgements and JSON Schemas for every event.
|
|
11
|
+
- Resource-style routes, string IDs, cursor pagination, `application/problem+json` errors with stable `code`s, typed messages with `attachment_id`.
|
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# @myronsi/messenger-api
|
|
2
|
+
|
|
3
|
+
The API contract of the Messenger backend, published to npm so that backend and frontend are built from the same source.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
api/
|
|
7
|
+
├─ openapi.yaml REST contract (OpenAPI 3.1); info.version = package version
|
|
8
|
+
├─ websocket/ JSON Schema per event + examples; websocket.md describes the protocol
|
|
9
|
+
├─ oapi-codegen.yaml Go server generation config
|
|
10
|
+
├─ CHANGELOG.md contract changes only
|
|
11
|
+
├─ package.json "name": "@myronsi/messenger-api"
|
|
12
|
+
└─ dist/ generated (not committed)
|
|
13
|
+
├─ openapi.yaml
|
|
14
|
+
├─ schema.d.ts REST types (openapi-typescript)
|
|
15
|
+
├─ ws-events.d.ts WebSocket event types (from the JSON Schemas)
|
|
16
|
+
├─ ws-events.schema.json bundled JSON Schemas (used by the breaking-change check)
|
|
17
|
+
├─ ws-docs.json websocket.md and the examples (used by the PATCH check)
|
|
18
|
+
└─ index.js export const API_VERSION = "2.0.0-alpha.1"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Use in the frontend
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npm install @myronsi/messenger-api
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { API_VERSION, type paths, type ServerEvent } from "@myronsi/messenger-api";
|
|
29
|
+
type Chats = paths["/chats"]["get"]["responses"]["200"]["content"]["application/json"];
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Send `API_VERSION` as `X-Client-Api-Version`. Dist-tags: `latest` is the last stable contract, `next` is the contract of the latest `master`, and pre-releases of a version (`2.0.0-alpha.N`) use `alpha`.
|
|
33
|
+
|
|
34
|
+
## Working on the contract
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
cd api
|
|
38
|
+
npm ci
|
|
39
|
+
npm run lint # Redocly lint
|
|
40
|
+
npm run check # package version == info.version; WebSocket examples match their schemas
|
|
41
|
+
npm run build # dist/
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Change the contract first, in the same PR as the code that implements it. Bump `info.version` **and** `package.json` `version` together (CI fails if they differ) as required by `docs/api-compatibility.md`; add an entry to `CHANGELOG.md`. Pull requests that touch `api/` get the `api-change` label, run the lint, the breaking-change check against the last released contract and the version-bump check (`.github/workflows/api-ci.yml`).
|
|
45
|
+
|
|
46
|
+
## Go server
|
|
47
|
+
|
|
48
|
+
The Go server code is generated from `openapi.yaml` with [oapi-codegen](https://github.com/oapi-codegen/oapi-codegen) (strict server) in the same PR as a contract change. The configuration is `oapi-codegen.yaml`; the generator was verified with oapi-codegen v2.8.0 (Go 1.25) against this document. Add this directive to the Go module and commit the generated file:
|
|
49
|
+
|
|
50
|
+
```go
|
|
51
|
+
//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@v2.8.0 -config api/oapi-codegen.yaml api/openapi.yaml
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
As soon as the repository has a `go.mod`, CI runs `go generate ./... && git diff --exit-code`.
|
|
55
|
+
|
|
56
|
+
## Publishing
|
|
57
|
+
|
|
58
|
+
See `docs/releasing.md`: `next` on every merge to `master` that changes `api/`, the stable version after a backend release when `info.version` is not on npm yet. Both use `npm publish` with Trusted Publishing, which also attaches provenance.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const API_VERSION = "2.0.0-alpha.1";
|