@myronsi/messenger-api 2.1.0-alpha.25.next.107 → 2.1.0-alpha.27.next.109

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 CHANGED
@@ -2,6 +2,25 @@
2
2
 
3
3
  Contract changes only. The backend changelog is `CHANGELOG.md` in the repository root. Rules: `docs/api-compatibility.md`.
4
4
 
5
+ ## 2.1.0-alpha.27
6
+
7
+ - `User` gains the required `profile_version` (grows with username, display name, bio or avatar changes, not with
8
+ presence) and `StickerPack` the required `version` (grows with title or sticker changes).
9
+ - `GET /me`, `GET /users/{user_id}`, `GET /groups/{chat_id}`, `GET /stickers/packs` and `GET /stickers/packs/{pack_id}`
10
+ send an `ETag` with `Cache-Control: private, no-cache` and answer `304` to a matching `If-None-Match`.
11
+ - `/attachments/{attachment_id}/content` is cached as immutable (an attachment never changes).
12
+ - New server WebSocket event `user_updated` (`user_id`, `profile_version`) for users who share a chat with the user.
13
+
14
+ ## 2.1.0-alpha.26
15
+
16
+ - `DELETE /chats/{chat_id}` takes `scope=me|everyone` (default `everyone`, as before). `me` deletes the direct chat
17
+ only for the caller: it leaves their list, its history so far stays hidden for them, and it comes back with only
18
+ newer messages when one arrives.
19
+ - `POST /chats/{chat_id}/clear` (`ClearHistoryRequest`, `scope: me|everyone`) clears the history up to the newest
20
+ message: for the caller only, or for every member (direct chats: either user; groups: owner and admins, else
21
+ `403`).
22
+ - New server WebSocket event `history_cleared` (`before_message_id`, `scope`, `actor_id`).
23
+
5
24
  ## 2.1.0-alpha.25
6
25
 
7
26
  - Archive: `PUT` and `DELETE /chats/{chat_id}/archive` archive a chat for the caller and move it back. `Chat` gains
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- /* Generated from api/openapi.yaml 2.1.0-alpha.25. Do not edit. */
2
- export declare const API_VERSION: "2.1.0-alpha.25";
1
+ /* Generated from api/openapi.yaml 2.1.0-alpha.27. Do not edit. */
2
+ export declare const API_VERSION: "2.1.0-alpha.27";
3
3
  export type { paths, components, operations } from "./schema.js";
4
4
  export * from "./ws-events.js";
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export const API_VERSION = "2.1.0-alpha.25";
1
+ export const API_VERSION = "2.1.0-alpha.27";
package/dist/openapi.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  openapi: 3.1.0
2
2
  info:
3
3
  title: Messenger API
4
- version: 2.1.0-alpha.25
4
+ version: 2.1.0-alpha.27
5
5
  summary: REST contract of the Messenger backend (v2).
6
6
  description: |
7
7
  Contract for the Go backend. The WebSocket protocol is described in `websocket/` and
@@ -329,6 +329,8 @@ paths:
329
329
  operationId: getMe
330
330
  summary: Current user
331
331
  responses:
332
+ "304":
333
+ description: Not modified; the response's `ETag` matches `If-None-Match`.
332
334
  "426": { $ref: "#/components/responses/ClientOutdated" }
333
335
  "400": { $ref: "#/components/responses/BadRequest" }
334
336
  "200":
@@ -795,6 +797,8 @@ paths:
795
797
  or a `deny` exception) is `404` unless the two share a chat. Your own profile is always found. Lookups are
796
798
  rate limited per user.
797
799
  responses:
800
+ "304":
801
+ description: Not modified; the response's `ETag` matches `If-None-Match`.
798
802
  "426": { $ref: "#/components/responses/ClientOutdated" }
799
803
  "400": { $ref: "#/components/responses/BadRequest" }
800
804
  "200":
@@ -1089,9 +1093,20 @@ paths:
1089
1093
  operationId: deleteChat
1090
1094
  summary: Delete a direct chat
1091
1095
  description: |
1092
- Deletes the chat and its messages for both users (as v1 did); both get `chat_deleted`.
1096
+ `scope=everyone` (the default) deletes the chat and its messages for both users (as v1 did); both get
1097
+ `chat_deleted`. `scope=me` deletes it only for the caller: the chat leaves their list and its history up to
1098
+ now is hidden for them (as `POST /chats/{chat_id}/clear` with `scope: me`); only the caller's devices get
1099
+ `chat_deleted`. When a newer message arrives the chat comes back for the caller with only the newer messages.
1093
1100
  For groups use `DELETE /groups/{chat_id}` (owner) or `POST /groups/{chat_id}/leave`;
1094
1101
  a group here is `422`.
1102
+ parameters:
1103
+ - name: scope
1104
+ in: query
1105
+ required: false
1106
+ schema:
1107
+ type: string
1108
+ enum: [me, everyone]
1109
+ default: everyone
1095
1110
  responses:
1096
1111
  "426": { $ref: "#/components/responses/ClientOutdated" }
1097
1112
  "400": { $ref: "#/components/responses/BadRequest" }
@@ -1131,6 +1146,35 @@ paths:
1131
1146
  description: Unpinned
1132
1147
  "401": { $ref: "#/components/responses/Unauthorized" }
1133
1148
  "404": { $ref: "#/components/responses/NotFound" }
1149
+ /chats/{chat_id}/clear:
1150
+ parameters:
1151
+ - $ref: "#/components/parameters/ClientVersion"
1152
+ - $ref: "#/components/parameters/ClientApiVersion"
1153
+ - $ref: "#/components/parameters/ChatId"
1154
+ post:
1155
+ tags: [chats]
1156
+ operationId: clearChatHistory
1157
+ summary: Clear the history of a chat
1158
+ description: |
1159
+ Clears every message up to the newest one now. `scope: me` hides them only for the caller (any member).
1160
+ `scope: everyone` removes them for every member: in a direct chat either user may do it, in a group the
1161
+ owner and admins (`403` for others). The chat itself stays. The caller's devices (`me`) or every member's
1162
+ (`everyone`) get `history_cleared`; messages up to `before_message_id` are no longer listed, counted as
1163
+ unread, found by search or shown as media.
1164
+ requestBody:
1165
+ required: true
1166
+ content:
1167
+ application/json:
1168
+ schema: { $ref: "#/components/schemas/ClearHistoryRequest" }
1169
+ responses:
1170
+ "426": { $ref: "#/components/responses/ClientOutdated" }
1171
+ "400": { $ref: "#/components/responses/BadRequest" }
1172
+ "204":
1173
+ description: Cleared
1174
+ "401": { $ref: "#/components/responses/Unauthorized" }
1175
+ "403": { $ref: "#/components/responses/Forbidden" }
1176
+ "404": { $ref: "#/components/responses/NotFound" }
1177
+ "422": { $ref: "#/components/responses/ValidationFailed" }
1134
1178
  /chats/{chat_id}/archive:
1135
1179
  parameters:
1136
1180
  - $ref: "#/components/parameters/ClientVersion"
@@ -1717,6 +1761,8 @@ paths:
1717
1761
  operationId: getGroup
1718
1762
  summary: Group details and members
1719
1763
  responses:
1764
+ "304":
1765
+ description: Not modified; the response's `ETag` matches `If-None-Match`.
1720
1766
  "426": { $ref: "#/components/responses/ClientOutdated" }
1721
1767
  "400": { $ref: "#/components/responses/BadRequest" }
1722
1768
  "200":
@@ -1934,6 +1980,8 @@ paths:
1934
1980
  required: false
1935
1981
  schema: { type: boolean, default: false }
1936
1982
  responses:
1983
+ "304":
1984
+ description: Not modified; the response's `ETag` matches `If-None-Match`.
1937
1985
  "426": { $ref: "#/components/responses/ClientOutdated" }
1938
1986
  "400": { $ref: "#/components/responses/BadRequest" }
1939
1987
  "200":
@@ -1980,6 +2028,8 @@ paths:
1980
2028
  `Sticker.pack_slug` with `GET /stickers/links/{slug}` instead. `is_installed` tells whether it is in the
1981
2029
  user's panel. A hidden pack is found only by its owner.
1982
2030
  responses:
2031
+ "304":
2032
+ description: Not modified; the response's `ETag` matches `If-None-Match`.
1983
2033
  "426": { $ref: "#/components/responses/ClientOutdated" }
1984
2034
  "400": { $ref: "#/components/responses/BadRequest" }
1985
2035
  "200":
@@ -4854,9 +4904,13 @@ components:
4854
4904
  User:
4855
4905
  type: object
4856
4906
  description: A user as visible to the requesting user; hidden fields are `null`.
4857
- required: [id, username, display_name, avatar_url, bio, is_online, last_seen, is_deleted]
4907
+ required: [id, username, display_name, avatar_url, bio, is_online, last_seen, is_deleted, profile_version]
4858
4908
  properties:
4859
4909
  id: { $ref: "#/components/schemas/Id" }
4910
+ profile_version:
4911
+ type: integer
4912
+ minimum: 0
4913
+ description: Grows whenever the username, display name, bio or avatar changes (not with presence). Clients keep a stored profile until a higher version arrives.
4860
4914
  username: { $ref: "#/components/schemas/Username" }
4861
4915
  display_name: { type: string }
4862
4916
  contact_name:
@@ -5075,9 +5129,13 @@ components:
5075
5129
  pattern: "^[A-Za-z0-9]{8,32}$"
5076
5130
  StickerPack:
5077
5131
  type: object
5078
- required: [id, title, is_official, is_installed, is_mine, is_hidden, stickers]
5132
+ required: [id, title, is_official, is_installed, is_mine, is_hidden, stickers, version]
5079
5133
  properties:
5080
5134
  id: { $ref: "#/components/schemas/Id" }
5135
+ version:
5136
+ type: integer
5137
+ minimum: 0
5138
+ description: Grows whenever the title or the stickers of the pack change.
5081
5139
  title: { type: string, minLength: 1, maxLength: 64 }
5082
5140
  is_official:
5083
5141
  type: boolean
@@ -5607,6 +5665,13 @@ components:
5607
5665
  type: array
5608
5666
  items: { $ref: "#/components/schemas/Chat" }
5609
5667
  next_cursor: { $ref: "#/components/schemas/Cursor" }
5668
+ ClearHistoryRequest:
5669
+ type: object
5670
+ required: [scope]
5671
+ properties:
5672
+ scope:
5673
+ type: string
5674
+ enum: [me, everyone]
5610
5675
  PinOrderRequest:
5611
5676
  type: object
5612
5677
  required: [chat_ids]
package/dist/schema.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- /* Generated from api/openapi.yaml 2.1.0-alpha.25. Do not edit. */
1
+ /* Generated from api/openapi.yaml 2.1.0-alpha.27. Do not edit. */
2
2
  export interface paths {
3
3
  "/meta": {
4
4
  parameters: {
@@ -855,7 +855,10 @@ export interface paths {
855
855
  post?: never;
856
856
  /**
857
857
  * Delete a direct chat
858
- * @description Deletes the chat and its messages for both users (as v1 did); both get `chat_deleted`.
858
+ * @description `scope=everyone` (the default) deletes the chat and its messages for both users (as v1 did); both get
859
+ * `chat_deleted`. `scope=me` deletes it only for the caller: the chat leaves their list and its history up to
860
+ * now is hidden for them (as `POST /chats/{chat_id}/clear` with `scope: me`); only the caller's devices get
861
+ * `chat_deleted`. When a newer message arrives the chat comes back for the caller with only the newer messages.
859
862
  * For groups use `DELETE /groups/{chat_id}` (owner) or `POST /groups/{chat_id}/leave`;
860
863
  * a group here is `422`.
861
864
  */
@@ -894,6 +897,37 @@ export interface paths {
894
897
  patch?: never;
895
898
  trace?: never;
896
899
  };
900
+ "/chats/{chat_id}/clear": {
901
+ parameters: {
902
+ query?: never;
903
+ header?: {
904
+ /** @description Version of the client app, for logs and the per-client metric. */
905
+ "X-Client-Version"?: components["parameters"]["ClientVersion"];
906
+ /** @description Contract version the client was built with (`API_VERSION` of `@myronsi/messenger-api`). A different MAJOR or a version below `min_client_api_version` is answered with `426`; a malformed value with `400` (`invalid_client_version`). */
907
+ "X-Client-Api-Version"?: components["parameters"]["ClientApiVersion"];
908
+ };
909
+ path: {
910
+ chat_id: components["parameters"]["ChatId"];
911
+ };
912
+ cookie?: never;
913
+ };
914
+ get?: never;
915
+ put?: never;
916
+ /**
917
+ * Clear the history of a chat
918
+ * @description Clears every message up to the newest one now. `scope: me` hides them only for the caller (any member).
919
+ * `scope: everyone` removes them for every member: in a direct chat either user may do it, in a group the
920
+ * owner and admins (`403` for others). The chat itself stays. The caller's devices (`me`) or every member's
921
+ * (`everyone`) get `history_cleared`; messages up to `before_message_id` are no longer listed, counted as
922
+ * unread, found by search or shown as media.
923
+ */
924
+ post: operations["clearChatHistory"];
925
+ delete?: never;
926
+ options?: never;
927
+ head?: never;
928
+ patch?: never;
929
+ trace?: never;
930
+ };
897
931
  "/chats/{chat_id}/archive": {
898
932
  parameters: {
899
933
  query?: never;
@@ -3209,6 +3243,8 @@ export interface components {
3209
3243
  /** @description A user as visible to the requesting user; hidden fields are `null`. */
3210
3244
  User: {
3211
3245
  id: components["schemas"]["Id"];
3246
+ /** @description Grows whenever the username, display name, bio or avatar changes (not with presence). Clients keep a stored profile until a higher version arrives. */
3247
+ profile_version: number;
3212
3248
  username: components["schemas"]["Username"];
3213
3249
  display_name: string;
3214
3250
  /** @description The requesting user's own name for this user, if set. */
@@ -3348,6 +3384,8 @@ export interface components {
3348
3384
  StickerPackSlug: string;
3349
3385
  StickerPack: {
3350
3386
  id: components["schemas"]["Id"];
3387
+ /** @description Grows whenever the title or the stickers of the pack change. */
3388
+ version: number;
3351
3389
  title: string;
3352
3390
  /** @description A built-in pack of the messenger, not made by a user. */
3353
3391
  is_official: boolean;
@@ -3606,6 +3644,10 @@ export interface components {
3606
3644
  items: components["schemas"]["Chat"][];
3607
3645
  next_cursor: components["schemas"]["Cursor"];
3608
3646
  };
3647
+ ClearHistoryRequest: {
3648
+ /** @enum {string} */
3649
+ scope: "me" | "everyone";
3650
+ };
3609
3651
  PinOrderRequest: {
3610
3652
  chat_ids: components["schemas"]["Id"][];
3611
3653
  };
@@ -4471,6 +4513,13 @@ export interface operations {
4471
4513
  "application/json": components["schemas"]["Me"];
4472
4514
  };
4473
4515
  };
4516
+ /** @description Not modified; the response's `ETag` matches `If-None-Match`. */
4517
+ 304: {
4518
+ headers: {
4519
+ [name: string]: unknown;
4520
+ };
4521
+ content?: never;
4522
+ };
4474
4523
  400: components["responses"]["BadRequest"];
4475
4524
  401: components["responses"]["Unauthorized"];
4476
4525
  426: components["responses"]["ClientOutdated"];
@@ -5167,6 +5216,13 @@ export interface operations {
5167
5216
  "application/json": components["schemas"]["User"];
5168
5217
  };
5169
5218
  };
5219
+ /** @description Not modified; the response's `ETag` matches `If-None-Match`. */
5220
+ 304: {
5221
+ headers: {
5222
+ [name: string]: unknown;
5223
+ };
5224
+ content?: never;
5225
+ };
5170
5226
  400: components["responses"]["BadRequest"];
5171
5227
  401: components["responses"]["Unauthorized"];
5172
5228
  404: components["responses"]["NotFound"];
@@ -5564,7 +5620,9 @@ export interface operations {
5564
5620
  };
5565
5621
  deleteChat: {
5566
5622
  parameters: {
5567
- query?: never;
5623
+ query?: {
5624
+ scope?: "me" | "everyone";
5625
+ };
5568
5626
  header?: {
5569
5627
  /** @description Version of the client app, for logs and the per-client metric. */
5570
5628
  "X-Client-Version"?: components["parameters"]["ClientVersion"];
@@ -5651,6 +5709,41 @@ export interface operations {
5651
5709
  426: components["responses"]["ClientOutdated"];
5652
5710
  };
5653
5711
  };
5712
+ clearChatHistory: {
5713
+ parameters: {
5714
+ query?: never;
5715
+ header?: {
5716
+ /** @description Version of the client app, for logs and the per-client metric. */
5717
+ "X-Client-Version"?: components["parameters"]["ClientVersion"];
5718
+ /** @description Contract version the client was built with (`API_VERSION` of `@myronsi/messenger-api`). A different MAJOR or a version below `min_client_api_version` is answered with `426`; a malformed value with `400` (`invalid_client_version`). */
5719
+ "X-Client-Api-Version"?: components["parameters"]["ClientApiVersion"];
5720
+ };
5721
+ path: {
5722
+ chat_id: components["parameters"]["ChatId"];
5723
+ };
5724
+ cookie?: never;
5725
+ };
5726
+ requestBody: {
5727
+ content: {
5728
+ "application/json": components["schemas"]["ClearHistoryRequest"];
5729
+ };
5730
+ };
5731
+ responses: {
5732
+ /** @description Cleared */
5733
+ 204: {
5734
+ headers: {
5735
+ [name: string]: unknown;
5736
+ };
5737
+ content?: never;
5738
+ };
5739
+ 400: components["responses"]["BadRequest"];
5740
+ 401: components["responses"]["Unauthorized"];
5741
+ 403: components["responses"]["Forbidden"];
5742
+ 404: components["responses"]["NotFound"];
5743
+ 422: components["responses"]["ValidationFailed"];
5744
+ 426: components["responses"]["ClientOutdated"];
5745
+ };
5746
+ };
5654
5747
  archiveChat: {
5655
5748
  parameters: {
5656
5749
  query?: never;
@@ -6429,6 +6522,13 @@ export interface operations {
6429
6522
  "application/json": components["schemas"]["Group"];
6430
6523
  };
6431
6524
  };
6525
+ /** @description Not modified; the response's `ETag` matches `If-None-Match`. */
6526
+ 304: {
6527
+ headers: {
6528
+ [name: string]: unknown;
6529
+ };
6530
+ content?: never;
6531
+ };
6432
6532
  400: components["responses"]["BadRequest"];
6433
6533
  401: components["responses"]["Unauthorized"];
6434
6534
  404: components["responses"]["NotFound"];
@@ -6768,6 +6868,13 @@ export interface operations {
6768
6868
  "application/json": components["schemas"]["StickerPackList"];
6769
6869
  };
6770
6870
  };
6871
+ /** @description Not modified; the response's `ETag` matches `If-None-Match`. */
6872
+ 304: {
6873
+ headers: {
6874
+ [name: string]: unknown;
6875
+ };
6876
+ content?: never;
6877
+ };
6771
6878
  400: components["responses"]["BadRequest"];
6772
6879
  401: components["responses"]["Unauthorized"];
6773
6880
  426: components["responses"]["ClientOutdated"];
@@ -6832,6 +6939,13 @@ export interface operations {
6832
6939
  "application/json": components["schemas"]["StickerPack"];
6833
6940
  };
6834
6941
  };
6942
+ /** @description Not modified; the response's `ETag` matches `If-None-Match`. */
6943
+ 304: {
6944
+ headers: {
6945
+ [name: string]: unknown;
6946
+ };
6947
+ content?: never;
6948
+ };
6835
6949
  400: components["responses"]["BadRequest"];
6836
6950
  401: components["responses"]["Unauthorized"];
6837
6951
  404: components["responses"]["NotFound"];
package/dist/ws-docs.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "markdown": "# WebSocket protocol (API contract v2)\r\n\r\nThe JSON Schemas in `websocket/client/` (client → server) and `websocket/server/` (server → client) are the source of truth. Every event has an example in `websocket/examples/`, validated against its schema by `npm run check`. TypeScript types are generated into `dist/ws-events.d.ts` (`ClientEvent`, `ServerEvent`).\r\n\r\n## Connecting\r\n\r\n1. `POST /api/v2/ws/ticket` (authenticated) returns `{ \"ticket\": \"…\", \"expires_in\": 30 }`. The ticket is single-use and short-lived, so no access token ends up in a URL or a log.\r\n2. Open **one connection per browser tab**: `wss://<host>/api/v2/ws?ticket=<ticket>&api_version=<contract version>`. The connection carries the events of all chats of the user. `api_version` is optional and takes the place of the `X-Client-Api-Version` header, which browsers cannot send on a WebSocket.\r\n3. The first server event is `hello` with `api_version` and `min_client_api_version`. A client that reconnects after a deploy compares them with the contract version it was built for and shows an upgrade notice instead of failing at random.\r\n4. When the ticket is invalid or expired the server closes the connection with code `4401`. A client whose `api_version` is no longer served is closed with `4426` after `hello`.\r\n\r\n## Close codes\r\n\r\n| Code | Meaning | Client |\r\n| --- | --- | --- |\r\n| `1012` | `reconnect`: the server is restarting, or it lost its pub/sub connection and events may be missing | reconnect with backoff, then load what was missed (`after` cursor) |\r\n| `1013` | the client did not keep up with its events, or sent more than 64 events that are not handled yet | reconnect, then catch up |\r\n| `4401` | invalid ticket, or the session ended (logout, revoked, password changed) | get a new ticket; if that fails, sign in again |\r\n| `4426` | the client's contract version is no longer served | show the upgrade notice |\r\n| `4429` | the user opened more than 10 connections on this server; the oldest one is closed | do not reconnect this tab automatically |\r\n\r\n## Envelope\r\n\r\nServer → client:\r\n\r\n```json\r\n{ \"type\": \"message\", \"event_id\": \"7217400317439950849\", \"chat_id\": \"42\", \"data\": { \"message\": { \"…\": \"…\" } } }\r\n```\r\n\r\nClient → server:\r\n\r\n```json\r\n{ \"type\": \"message\", \"client_temp_id\": \"c-1\", \"chat_id\": \"42\", \"data\": { \"type\": \"text\", \"content\": \"Hello!\" } }\r\n```\r\n\r\n- All IDs are strings (Snowflake IDs do not fit into a JavaScript number).\r\n- `event_id` is unique and increases per server; it is only for deduplication and logs.\r\n- `chat_id` is always `null` in `hello`, `presence` and `approval_request_created`, which do not belong to a chat. `ack` and `error` repeat the `chat_id` of the client event they answer, and it is `null` for connection-level errors.\r\n- Unknown event `type`s must be ignored by clients, so new event types are not a breaking change.\r\n- A user who is removed from a chat (or whose chat is deleted) receives `chat_deleted` and no further events of that chat.\r\n\r\n## Acknowledgements\r\n\r\nEvery client event except `typing` (which is not acknowledged and carries no `client_temp_id`) has a `client_temp_id` (1–64 characters, unique per client). The server answers with exactly one of:\r\n\r\n- `ack` — `client_temp_id`, and for `message` the stored `message_id` and `created_at`. Sending the same `client_temp_id` again returns the same `ack` (idempotent), which makes retries after a reconnect safe.\r\n- `error` — `client_temp_id` and `data.code`/`data.message`. `code` is one of the stable codes of `ErrorCode` in `openapi.yaml` (the same codes as the REST `application/problem+json` errors).\r\n\r\nThe sender also receives the broadcast `message` event with the stored message (its `client_temp_id` is included, so the client can replace its pending copy).\r\n\r\n## Client → server events\r\n\r\n| Type | Purpose |\r\n| --- | --- |\r\n| `message` | Send a message (`type` `text`, `file` or `voice`; files are referenced by `attachment_id`, never by URL) |\r\n| `resend` | Deliver a stored but undelivered message again |\r\n| `edit` | Edit your own text message |\r\n| `delete` | Delete a message for yourself (`scope: me`) or everyone |\r\n| `read` | Mark messages as read up to `message_id` |\r\n| `reaction_add`, `reaction_remove` | Add or remove a reaction |\r\n| `typing` | Typing, recording a voice message, choosing a sticker or sending a photo, video or file (`action`, not acknowledged). Repeat `is_typing: true` every 3 s while it lasts, send `false` when it ends |\r\n\r\n## Server → client events\r\n\r\n| Type | Meaning |\r\n| --- | --- |\r\n| `hello` | First event: `api_version`, `min_client_api_version`, `user_id` |\r\n| `ack`, `error` | Result of a client event, references `client_temp_id` |\r\n| `message`, `edit`, `delete` | Message created, edited or deleted |\r\n| `reaction_add`, `reaction_remove` | Reactions changed |\r\n| `read` | A user read up to `message_id` |\r\n| `typing` | A user is typing, recording a voice message, choosing a sticker or sending a photo, video or file (`action`); hide it after 6 s without a repeat |\r\n| `chat_created`, `chat_deleted`, `chat_list_update` | Chat list changes |\r\n| `group_created`, `group_updated` | Group changes (members, roles, name, avatar) |\r\n| `approval_request_created` | New request in the inbox |\r\n| `presence` | A user came online or went offline |\n| `call_updated` | A call of the chat changed (state, participants, epoch); carries the whole call, keep the highest `version` |\n| `call_keys` | Sealed call sender keys for this session only (`docs/calls-e2ee.md`) |\r\n\r\n## Compatibility\r\n\r\nAdding an event type or an optional field is a MINOR change; removing or renaming an event or field, or making a field required, is MAJOR (see `docs/api-compatibility.md`). Clients must ignore unknown events and unknown fields.\r\n",
2
+ "markdown": "# WebSocket protocol (API contract v2)\r\n\r\nThe JSON Schemas in `websocket/client/` (client → server) and `websocket/server/` (server → client) are the source of truth. Every event has an example in `websocket/examples/`, validated against its schema by `npm run check`. TypeScript types are generated into `dist/ws-events.d.ts` (`ClientEvent`, `ServerEvent`).\r\n\r\n## Connecting\r\n\r\n1. `POST /api/v2/ws/ticket` (authenticated) returns `{ \"ticket\": \"…\", \"expires_in\": 30 }`. The ticket is single-use and short-lived, so no access token ends up in a URL or a log.\r\n2. Open **one connection per browser tab**: `wss://<host>/api/v2/ws?ticket=<ticket>&api_version=<contract version>`. The connection carries the events of all chats of the user. `api_version` is optional and takes the place of the `X-Client-Api-Version` header, which browsers cannot send on a WebSocket.\r\n3. The first server event is `hello` with `api_version` and `min_client_api_version`. A client that reconnects after a deploy compares them with the contract version it was built for and shows an upgrade notice instead of failing at random.\r\n4. When the ticket is invalid or expired the server closes the connection with code `4401`. A client whose `api_version` is no longer served is closed with `4426` after `hello`.\r\n\r\n## Close codes\r\n\r\n| Code | Meaning | Client |\r\n| --- | --- | --- |\r\n| `1012` | `reconnect`: the server is restarting, or it lost its pub/sub connection and events may be missing | reconnect with backoff, then load what was missed (`after` cursor) |\r\n| `1013` | the client did not keep up with its events, or sent more than 64 events that are not handled yet | reconnect, then catch up |\r\n| `4401` | invalid ticket, or the session ended (logout, revoked, password changed) | get a new ticket; if that fails, sign in again |\r\n| `4426` | the client's contract version is no longer served | show the upgrade notice |\r\n| `4429` | the user opened more than 10 connections on this server; the oldest one is closed | do not reconnect this tab automatically |\r\n\r\n## Envelope\r\n\r\nServer → client:\r\n\r\n```json\r\n{ \"type\": \"message\", \"event_id\": \"7217400317439950849\", \"chat_id\": \"42\", \"data\": { \"message\": { \"…\": \"…\" } } }\r\n```\r\n\r\nClient → server:\r\n\r\n```json\r\n{ \"type\": \"message\", \"client_temp_id\": \"c-1\", \"chat_id\": \"42\", \"data\": { \"type\": \"text\", \"content\": \"Hello!\" } }\r\n```\r\n\r\n- All IDs are strings (Snowflake IDs do not fit into a JavaScript number).\r\n- `event_id` is unique and increases per server; it is only for deduplication and logs.\r\n- `chat_id` is always `null` in `hello`, `presence` and `approval_request_created`, which do not belong to a chat. `ack` and `error` repeat the `chat_id` of the client event they answer, and it is `null` for connection-level errors.\r\n- Unknown event `type`s must be ignored by clients, so new event types are not a breaking change.\r\n- A user who is removed from a chat (or whose chat is deleted) receives `chat_deleted` and no further events of that chat.\r\n\r\n## Acknowledgements\r\n\r\nEvery client event except `typing` (which is not acknowledged and carries no `client_temp_id`) has a `client_temp_id` (1–64 characters, unique per client). The server answers with exactly one of:\r\n\r\n- `ack` — `client_temp_id`, and for `message` the stored `message_id` and `created_at`. Sending the same `client_temp_id` again returns the same `ack` (idempotent), which makes retries after a reconnect safe.\r\n- `error` — `client_temp_id` and `data.code`/`data.message`. `code` is one of the stable codes of `ErrorCode` in `openapi.yaml` (the same codes as the REST `application/problem+json` errors).\r\n\r\nThe sender also receives the broadcast `message` event with the stored message (its `client_temp_id` is included, so the client can replace its pending copy).\r\n\r\n## Client → server events\r\n\r\n| Type | Purpose |\r\n| --- | --- |\r\n| `message` | Send a message (`type` `text`, `file` or `voice`; files are referenced by `attachment_id`, never by URL) |\r\n| `resend` | Deliver a stored but undelivered message again |\r\n| `edit` | Edit your own text message |\r\n| `delete` | Delete a message for yourself (`scope: me`) or everyone |\r\n| `read` | Mark messages as read up to `message_id` |\r\n| `reaction_add`, `reaction_remove` | Add or remove a reaction |\r\n| `typing` | Typing, recording a voice message, choosing a sticker or sending a photo, video or file (`action`, not acknowledged). Repeat `is_typing: true` every 3 s while it lasts, send `false` when it ends |\r\n\r\n## Server → client events\r\n\r\n| Type | Meaning |\r\n| --- | --- |\r\n| `hello` | First event: `api_version`, `min_client_api_version`, `user_id` |\r\n| `ack`, `error` | Result of a client event, references `client_temp_id` |\r\n| `message`, `edit`, `delete` | Message created, edited or deleted |\r\n| `reaction_add`, `reaction_remove` | Reactions changed |\r\n| `read` | A user read up to `message_id` |\r\n| `typing` | A user is typing, recording a voice message, choosing a sticker or sending a photo, video or file (`action`); hide it after 6 s without a repeat |\r\n| `chat_created`, `chat_deleted`, `chat_list_update` | Chat list changes |\n| `history_cleared` | Messages up to `before_message_id` were cleared for you (`scope: me`) or everyone |\r\n| `group_created`, `group_updated` | Group changes (members, roles, name, avatar) |\r\n| `approval_request_created` | New request in the inbox |\r\n| `presence` | A user came online or went offline |\n| `user_updated` | A user you share a chat with changed their profile (`profile_version`) |\n| `call_updated` | A call of the chat changed (state, participants, epoch); carries the whole call, keep the highest `version` |\n| `call_keys` | Sealed call sender keys for this session only (`docs/calls-e2ee.md`) |\r\n\r\n## Compatibility\r\n\r\nAdding an event type or an optional field is a MINOR change; removing or renaming an event or field, or making a field required, is MAJOR (see `docs/api-compatibility.md`). Clients must ignore unknown events and unknown fields.\r\n",
3
3
  "examples": {
4
4
  "client/delete.json": {
5
5
  "type": "delete",
@@ -97,7 +97,8 @@
97
97
  "bio": null,
98
98
  "is_online": true,
99
99
  "last_seen": null,
100
- "is_deleted": false
100
+ "is_deleted": false,
101
+ "profile_version": 1
101
102
  },
102
103
  "group_name": null,
103
104
  "preview": "Hi, can we talk?",
@@ -187,7 +188,8 @@
187
188
  "bio": null,
188
189
  "is_online": true,
189
190
  "last_seen": null,
190
- "is_deleted": false
191
+ "is_deleted": false,
192
+ "profile_version": 1
191
193
  },
192
194
  "is_pinned": false,
193
195
  "pin_position": null,
@@ -207,7 +209,8 @@
207
209
  "bio": null,
208
210
  "is_online": true,
209
211
  "last_seen": null,
210
- "is_deleted": false
212
+ "is_deleted": false,
213
+ "profile_version": 1
211
214
  },
212
215
  "content": "Hello!",
213
216
  "attachment": null,
@@ -249,7 +252,8 @@
249
252
  "bio": null,
250
253
  "is_online": true,
251
254
  "last_seen": null,
252
- "is_deleted": false
255
+ "is_deleted": false,
256
+ "profile_version": 1
253
257
  },
254
258
  "is_pinned": false,
255
259
  "pin_position": null,
@@ -269,7 +273,8 @@
269
273
  "bio": null,
270
274
  "is_online": true,
271
275
  "last_seen": null,
272
- "is_deleted": false
276
+ "is_deleted": false,
277
+ "profile_version": 1
273
278
  },
274
279
  "content": "Hello!",
275
280
  "attachment": null,
@@ -313,7 +318,8 @@
313
318
  "bio": null,
314
319
  "is_online": true,
315
320
  "last_seen": null,
316
- "is_deleted": false
321
+ "is_deleted": false,
322
+ "profile_version": 1
317
323
  },
318
324
  "content": "Hello, world!",
319
325
  "attachment": null,
@@ -360,7 +366,8 @@
360
366
  "bio": null,
361
367
  "is_online": true,
362
368
  "last_seen": null,
363
- "is_deleted": false
369
+ "is_deleted": false,
370
+ "profile_version": 1
364
371
  },
365
372
  "role": "owner",
366
373
  "joined_at": "2026-10-04T12:00:00Z"
@@ -392,7 +399,8 @@
392
399
  "bio": null,
393
400
  "is_online": true,
394
401
  "last_seen": null,
395
- "is_deleted": false
402
+ "is_deleted": false,
403
+ "profile_version": 1
396
404
  },
397
405
  "role": "owner",
398
406
  "joined_at": "2026-10-04T12:00:00Z"
@@ -412,6 +420,16 @@
412
420
  "user_id": "1001"
413
421
  }
414
422
  },
423
+ "server/history_cleared.json": {
424
+ "type": "history_cleared",
425
+ "event_id": "7217400317439950011",
426
+ "chat_id": "42",
427
+ "data": {
428
+ "before_message_id": "7217400317439950002",
429
+ "scope": "everyone",
430
+ "actor_id": "7"
431
+ }
432
+ },
415
433
  "server/message.json": {
416
434
  "type": "message",
417
435
  "event_id": "7217400317439950009",
@@ -429,7 +447,8 @@
429
447
  "bio": null,
430
448
  "is_online": true,
431
449
  "last_seen": null,
432
- "is_deleted": false
450
+ "is_deleted": false,
451
+ "profile_version": 1
433
452
  },
434
453
  "content": "Hello!",
435
454
  "attachment": null,
@@ -535,6 +554,15 @@
535
554
  "is_typing": true,
536
555
  "action": "recording_voice"
537
556
  }
557
+ },
558
+ "server/user_updated.json": {
559
+ "type": "user_updated",
560
+ "event_id": "7217400317439950012",
561
+ "chat_id": null,
562
+ "data": {
563
+ "user_id": "7",
564
+ "profile_version": 3
565
+ }
538
566
  }
539
567
  }
540
568
  }
@@ -1,4 +1,4 @@
1
- /* Generated from api/openapi.yaml 2.1.0-alpha.25. Do not edit. */
1
+ /* Generated from api/openapi.yaml 2.1.0-alpha.27. Do not edit. */
2
2
 
3
3
  /**
4
4
  * Any WebSocket event, in either direction.
@@ -45,6 +45,7 @@ export type ServerEvent =
45
45
  | ServerGroupCreatedEvent
46
46
  | ServerGroupUpdatedEvent
47
47
  | ServerHelloEvent
48
+ | ServerHistoryClearedEvent
48
49
  | ServerMessageEvent
49
50
  | ServerPresenceEvent
50
51
  | ServerReactionAddEvent
@@ -53,7 +54,8 @@ export type ServerEvent =
53
54
  | ServerRecoveryRequestEvent
54
55
  | ServerSecurityAlertEvent
55
56
  | ServerSecurityNoticeEvent
56
- | ServerTypingEvent;
57
+ | ServerTypingEvent
58
+ | ServerUserUpdatedEvent;
57
59
  export type Timestamp = string;
58
60
  export type ApprovalRequestType = "direct_message" | "group_invite";
59
61
  export type ApprovalRequestStatus = "pending" | "approved" | "rejected";
@@ -291,6 +293,10 @@ export interface ApprovalRequest {
291
293
  */
292
294
  export interface User {
293
295
  id: Id;
296
+ /**
297
+ * Grows whenever the username, display name, bio or avatar changes (not with presence). Clients keep a stored profile until a higher version arrives.
298
+ */
299
+ profile_version: number;
294
300
  username: Username;
295
301
  display_name: string;
296
302
  /**
@@ -754,6 +760,19 @@ export interface ServerHelloEvent {
754
760
  user_id: Id;
755
761
  };
756
762
  }
763
+ /**
764
+ * Messages of the chat up to before_message_id were cleared, for you (scope me) or for every member (scope everyone). Drop them from what you show.
765
+ */
766
+ export interface ServerHistoryClearedEvent {
767
+ type: "history_cleared";
768
+ event_id: Id;
769
+ chat_id: Id;
770
+ data: {
771
+ before_message_id: Id;
772
+ scope: "me" | "everyone";
773
+ actor_id: Id;
774
+ };
775
+ }
757
776
  /**
758
777
  * A new message in a chat.
759
778
  */
@@ -906,3 +925,15 @@ export interface ServerTypingEvent {
906
925
  "typing" | "recording_voice" | "choosing_sticker" | "uploading_photo" | "uploading_video" | "uploading_file";
907
926
  };
908
927
  }
928
+ /**
929
+ * A user you share a chat with changed their username, display name, bio or avatar. Fetch GET /users/{user_id} again when profile_version is higher than the one you keep.
930
+ */
931
+ export interface ServerUserUpdatedEvent {
932
+ type: "user_updated";
933
+ event_id: Id;
934
+ chat_id: null;
935
+ data: {
936
+ user_id: Id;
937
+ profile_version: number;
938
+ };
939
+ }
@@ -1011,12 +1011,18 @@
1011
1011
  "bio",
1012
1012
  "is_online",
1013
1013
  "last_seen",
1014
- "is_deleted"
1014
+ "is_deleted",
1015
+ "profile_version"
1015
1016
  ],
1016
1017
  "properties": {
1017
1018
  "id": {
1018
1019
  "$ref": "#/$defs/Id"
1019
1020
  },
1021
+ "profile_version": {
1022
+ "type": "integer",
1023
+ "minimum": 0,
1024
+ "description": "Grows whenever the username, display name, bio or avatar changes (not with presence). Clients keep a stored profile until a higher version arrives."
1025
+ },
1020
1026
  "username": {
1021
1027
  "$ref": "#/$defs/Username"
1022
1028
  },
@@ -1512,12 +1518,18 @@
1512
1518
  "is_installed",
1513
1519
  "is_mine",
1514
1520
  "is_hidden",
1515
- "stickers"
1521
+ "stickers",
1522
+ "version"
1516
1523
  ],
1517
1524
  "properties": {
1518
1525
  "id": {
1519
1526
  "$ref": "#/$defs/Id"
1520
1527
  },
1528
+ "version": {
1529
+ "type": "integer",
1530
+ "minimum": 0,
1531
+ "description": "Grows whenever the title or the stickers of the pack change."
1532
+ },
1521
1533
  "title": {
1522
1534
  "type": "string",
1523
1535
  "minLength": 1,
@@ -2650,6 +2662,21 @@
2650
2662
  }
2651
2663
  }
2652
2664
  },
2665
+ "ClearHistoryRequest": {
2666
+ "type": "object",
2667
+ "required": [
2668
+ "scope"
2669
+ ],
2670
+ "properties": {
2671
+ "scope": {
2672
+ "type": "string",
2673
+ "enum": [
2674
+ "me",
2675
+ "everyone"
2676
+ ]
2677
+ }
2678
+ }
2679
+ },
2653
2680
  "PinOrderRequest": {
2654
2681
  "type": "object",
2655
2682
  "required": [
@@ -4758,6 +4785,51 @@
4758
4785
  "data"
4759
4786
  ]
4760
4787
  },
4788
+ "ServerHistoryClearedEvent": {
4789
+ "title": "ServerHistoryClearedEvent",
4790
+ "description": "Messages of the chat up to before_message_id were cleared, for you (scope me) or for every member (scope everyone). Drop them from what you show.",
4791
+ "type": "object",
4792
+ "properties": {
4793
+ "type": {
4794
+ "const": "history_cleared"
4795
+ },
4796
+ "event_id": {
4797
+ "$ref": "#/$defs/Id"
4798
+ },
4799
+ "chat_id": {
4800
+ "$ref": "#/$defs/Id"
4801
+ },
4802
+ "data": {
4803
+ "type": "object",
4804
+ "properties": {
4805
+ "before_message_id": {
4806
+ "$ref": "#/$defs/Id"
4807
+ },
4808
+ "scope": {
4809
+ "type": "string",
4810
+ "enum": [
4811
+ "me",
4812
+ "everyone"
4813
+ ]
4814
+ },
4815
+ "actor_id": {
4816
+ "$ref": "#/$defs/Id"
4817
+ }
4818
+ },
4819
+ "required": [
4820
+ "before_message_id",
4821
+ "scope",
4822
+ "actor_id"
4823
+ ]
4824
+ }
4825
+ },
4826
+ "required": [
4827
+ "type",
4828
+ "event_id",
4829
+ "chat_id",
4830
+ "data"
4831
+ ]
4832
+ },
4761
4833
  "ServerMessageEvent": {
4762
4834
  "title": "ServerMessageEvent",
4763
4835
  "description": "A new message in a chat.",
@@ -5166,6 +5238,44 @@
5166
5238
  "data"
5167
5239
  ]
5168
5240
  },
5241
+ "ServerUserUpdatedEvent": {
5242
+ "title": "ServerUserUpdatedEvent",
5243
+ "description": "A user you share a chat with changed their username, display name, bio or avatar. Fetch GET /users/{user_id} again when profile_version is higher than the one you keep.",
5244
+ "type": "object",
5245
+ "properties": {
5246
+ "type": {
5247
+ "const": "user_updated"
5248
+ },
5249
+ "event_id": {
5250
+ "$ref": "#/$defs/Id"
5251
+ },
5252
+ "chat_id": {
5253
+ "type": "null"
5254
+ },
5255
+ "data": {
5256
+ "type": "object",
5257
+ "properties": {
5258
+ "user_id": {
5259
+ "$ref": "#/$defs/Id"
5260
+ },
5261
+ "profile_version": {
5262
+ "type": "integer",
5263
+ "minimum": 0
5264
+ }
5265
+ },
5266
+ "required": [
5267
+ "user_id",
5268
+ "profile_version"
5269
+ ]
5270
+ }
5271
+ },
5272
+ "required": [
5273
+ "type",
5274
+ "event_id",
5275
+ "chat_id",
5276
+ "data"
5277
+ ]
5278
+ },
5169
5279
  "ClientEvent": {
5170
5280
  "title": "ClientEvent",
5171
5281
  "description": "Every event a client may send.",
@@ -5239,6 +5349,9 @@
5239
5349
  {
5240
5350
  "$ref": "#/$defs/ServerHelloEvent"
5241
5351
  },
5352
+ {
5353
+ "$ref": "#/$defs/ServerHistoryClearedEvent"
5354
+ },
5242
5355
  {
5243
5356
  "$ref": "#/$defs/ServerMessageEvent"
5244
5357
  },
@@ -5265,6 +5378,9 @@
5265
5378
  },
5266
5379
  {
5267
5380
  "$ref": "#/$defs/ServerTypingEvent"
5381
+ },
5382
+ {
5383
+ "$ref": "#/$defs/ServerUserUpdatedEvent"
5268
5384
  }
5269
5385
  ]
5270
5386
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myronsi/messenger-api",
3
- "version": "2.1.0-alpha.25.next.107",
3
+ "version": "2.1.0-alpha.27.next.109",
4
4
  "description": "API contract of the Messenger backend: OpenAPI document, WebSocket event schemas and generated TypeScript types",
5
5
  "license": "MIT",
6
6
  "repository": {