@myronsi/messenger-api 2.1.0-alpha.3.next.67 → 2.1.0-alpha.30

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/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 | 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\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 indicator (not acknowledged) |\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 |\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 |\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",
@@ -66,7 +66,8 @@
66
66
  "type": "typing",
67
67
  "chat_id": "42",
68
68
  "data": {
69
- "is_typing": true
69
+ "is_typing": true,
70
+ "action": "recording_voice"
70
71
  }
71
72
  },
72
73
  "server/ack.json": {
@@ -94,9 +95,14 @@
94
95
  "display_name": "Alice",
95
96
  "avatar_url": "/api/v2/users/1001/avatar",
96
97
  "bio": null,
98
+ "pronouns": null,
99
+ "birthday": null,
100
+ "music": null,
101
+ "background": null,
97
102
  "is_online": true,
98
103
  "last_seen": null,
99
- "is_deleted": false
104
+ "is_deleted": false,
105
+ "profile_version": 1
100
106
  },
101
107
  "group_name": null,
102
108
  "preview": "Hi, can we talk?",
@@ -104,6 +110,70 @@
104
110
  }
105
111
  }
106
112
  },
113
+ "server/call_keys.json": {
114
+ "type": "call_keys",
115
+ "event_id": "7217400317439950111",
116
+ "chat_id": "77",
117
+ "data": {
118
+ "call_id": "7217400317439950100",
119
+ "epoch": 2,
120
+ "items": [
121
+ {
122
+ "epoch": 2,
123
+ "sender_user_id": "1002",
124
+ "sender_session_id": "9c1d2e3f-4a5b-4c6d-8e7f-001122334455",
125
+ "recipient_session_id": "5b0e8f0a-3f1c-4a52-9a8e-0d6e1c3f9b21",
126
+ "enc": "BJCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC",
127
+ "ciphertext": "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
128
+ }
129
+ ]
130
+ }
131
+ },
132
+ "server/call_updated.json": {
133
+ "type": "call_updated",
134
+ "event_id": "7217400317439950110",
135
+ "chat_id": "77",
136
+ "data": {
137
+ "call": {
138
+ "id": "7217400317439950100",
139
+ "chat_id": "77",
140
+ "kind": "group",
141
+ "state": "active",
142
+ "end_reason": null,
143
+ "initiator_id": "1001",
144
+ "created_at": "2026-11-07T12:00:00Z",
145
+ "started_at": "2026-11-07T12:00:05Z",
146
+ "ended_at": null,
147
+ "ring_expires_at": "2026-11-07T12:00:30Z",
148
+ "epoch": 2,
149
+ "version": 4,
150
+ "max_participants": 10,
151
+ "participants": [
152
+ {
153
+ "user_id": "1001",
154
+ "state": "joined",
155
+ "session_id": "5b0e8f0a-3f1c-4a52-9a8e-0d6e1c3f9b21",
156
+ "identity_key": "BAt2AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
157
+ "joined_at": "2026-11-07T12:00:01Z"
158
+ },
159
+ {
160
+ "user_id": "1002",
161
+ "state": "joined",
162
+ "session_id": "9c1d2e3f-4a5b-4c6d-8e7f-001122334455",
163
+ "identity_key": "BHk9BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
164
+ "joined_at": "2026-11-07T12:00:05Z"
165
+ },
166
+ {
167
+ "user_id": "1003",
168
+ "state": "ringing",
169
+ "session_id": null,
170
+ "identity_key": null,
171
+ "joined_at": null
172
+ }
173
+ ]
174
+ }
175
+ }
176
+ },
107
177
  "server/chat_created.json": {
108
178
  "type": "chat_created",
109
179
  "event_id": "7217400317439950009",
@@ -120,12 +190,21 @@
120
190
  "display_name": "Alice",
121
191
  "avatar_url": "/api/v2/users/1001/avatar",
122
192
  "bio": null,
193
+ "pronouns": null,
194
+ "birthday": null,
195
+ "music": null,
196
+ "background": null,
123
197
  "is_online": true,
124
198
  "last_seen": null,
125
- "is_deleted": false
199
+ "is_deleted": false,
200
+ "profile_version": 1
126
201
  },
127
202
  "is_pinned": false,
203
+ "pin_position": null,
204
+ "is_archived": false,
128
205
  "unread_count": 1,
206
+ "first_unread_message_id": "7217400317439950001",
207
+ "last_read_message_id": null,
129
208
  "last_message": {
130
209
  "id": "7217400317439950001",
131
210
  "chat_id": "42",
@@ -136,9 +215,14 @@
136
215
  "display_name": "Alice",
137
216
  "avatar_url": "/api/v2/users/1001/avatar",
138
217
  "bio": null,
218
+ "pronouns": null,
219
+ "birthday": null,
220
+ "music": null,
221
+ "background": null,
139
222
  "is_online": true,
140
223
  "last_seen": null,
141
- "is_deleted": false
224
+ "is_deleted": false,
225
+ "profile_version": 1
142
226
  },
143
227
  "content": "Hello!",
144
228
  "attachment": null,
@@ -178,12 +262,21 @@
178
262
  "display_name": "Alice",
179
263
  "avatar_url": "/api/v2/users/1001/avatar",
180
264
  "bio": null,
265
+ "pronouns": null,
266
+ "birthday": null,
267
+ "music": null,
268
+ "background": null,
181
269
  "is_online": true,
182
270
  "last_seen": null,
183
- "is_deleted": false
271
+ "is_deleted": false,
272
+ "profile_version": 1
184
273
  },
185
274
  "is_pinned": false,
275
+ "pin_position": null,
276
+ "is_archived": false,
186
277
  "unread_count": 1,
278
+ "first_unread_message_id": "7217400317439950001",
279
+ "last_read_message_id": null,
187
280
  "last_message": {
188
281
  "id": "7217400317439950001",
189
282
  "chat_id": "42",
@@ -194,9 +287,14 @@
194
287
  "display_name": "Alice",
195
288
  "avatar_url": "/api/v2/users/1001/avatar",
196
289
  "bio": null,
290
+ "pronouns": null,
291
+ "birthday": null,
292
+ "music": null,
293
+ "background": null,
197
294
  "is_online": true,
198
295
  "last_seen": null,
199
- "is_deleted": false
296
+ "is_deleted": false,
297
+ "profile_version": 1
200
298
  },
201
299
  "content": "Hello!",
202
300
  "attachment": null,
@@ -238,9 +336,14 @@
238
336
  "display_name": "Alice",
239
337
  "avatar_url": "/api/v2/users/1001/avatar",
240
338
  "bio": null,
339
+ "pronouns": null,
340
+ "birthday": null,
341
+ "music": null,
342
+ "background": null,
241
343
  "is_online": true,
242
344
  "last_seen": null,
243
- "is_deleted": false
345
+ "is_deleted": false,
346
+ "profile_version": 1
244
347
  },
245
348
  "content": "Hello, world!",
246
349
  "attachment": null,
@@ -275,6 +378,7 @@
275
378
  "name": "Team",
276
379
  "description": null,
277
380
  "avatar_url": null,
381
+ "background": null,
278
382
  "owner_id": "1001",
279
383
  "my_role": "owner",
280
384
  "members": [
@@ -285,9 +389,14 @@
285
389
  "display_name": "Alice",
286
390
  "avatar_url": "/api/v2/users/1001/avatar",
287
391
  "bio": null,
392
+ "pronouns": null,
393
+ "birthday": null,
394
+ "music": null,
395
+ "background": null,
288
396
  "is_online": true,
289
397
  "last_seen": null,
290
- "is_deleted": false
398
+ "is_deleted": false,
399
+ "profile_version": 1
291
400
  },
292
401
  "role": "owner",
293
402
  "joined_at": "2026-10-04T12:00:00Z"
@@ -307,6 +416,7 @@
307
416
  "name": "Team",
308
417
  "description": null,
309
418
  "avatar_url": null,
419
+ "background": null,
310
420
  "owner_id": "1001",
311
421
  "my_role": "owner",
312
422
  "members": [
@@ -317,9 +427,14 @@
317
427
  "display_name": "Alice",
318
428
  "avatar_url": "/api/v2/users/1001/avatar",
319
429
  "bio": null,
430
+ "pronouns": null,
431
+ "birthday": null,
432
+ "music": null,
433
+ "background": null,
320
434
  "is_online": true,
321
435
  "last_seen": null,
322
- "is_deleted": false
436
+ "is_deleted": false,
437
+ "profile_version": 1
323
438
  },
324
439
  "role": "owner",
325
440
  "joined_at": "2026-10-04T12:00:00Z"
@@ -339,6 +454,16 @@
339
454
  "user_id": "1001"
340
455
  }
341
456
  },
457
+ "server/history_cleared.json": {
458
+ "type": "history_cleared",
459
+ "event_id": "7217400317439950011",
460
+ "chat_id": "42",
461
+ "data": {
462
+ "before_message_id": "7217400317439950002",
463
+ "scope": "everyone",
464
+ "actor_id": "7"
465
+ }
466
+ },
342
467
  "server/message.json": {
343
468
  "type": "message",
344
469
  "event_id": "7217400317439950009",
@@ -354,9 +479,14 @@
354
479
  "display_name": "Alice",
355
480
  "avatar_url": "/api/v2/users/1001/avatar",
356
481
  "bio": null,
482
+ "pronouns": null,
483
+ "birthday": null,
484
+ "music": null,
485
+ "background": null,
357
486
  "is_online": true,
358
487
  "last_seen": null,
359
- "is_deleted": false
488
+ "is_deleted": false,
489
+ "profile_version": 1
360
490
  },
361
491
  "content": "Hello!",
362
492
  "attachment": null,
@@ -415,6 +545,36 @@
415
545
  "read_at": "2026-10-04T12:00:00Z"
416
546
  }
417
547
  },
548
+ "server/recovery_request.json": {
549
+ "type": "recovery_request",
550
+ "event_id": "7217400317439950849",
551
+ "chat_id": null,
552
+ "data": {
553
+ "request_id": "z8uFZt0xFYtjm_iO3vI9xFYxsy7xM4K5uM1g1s8YbYI",
554
+ "user_agent": "Chrome on Windows",
555
+ "location": {
556
+ "city": "Berlin",
557
+ "country_code": "DE",
558
+ "country": "Germany"
559
+ },
560
+ "choices": [
561
+ 17,
562
+ 42,
563
+ 85
564
+ ],
565
+ "expires_at": "2026-11-05T20:00:00Z"
566
+ }
567
+ },
568
+ "server/security_alert.json": {
569
+ "type": "security_alert",
570
+ "event_id": "7217400317439950010",
571
+ "chat_id": null,
572
+ "data": {
573
+ "type": "login",
574
+ "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/140.0",
575
+ "created_at": "2026-11-06T12:00:00Z"
576
+ }
577
+ },
418
578
  "server/security_notice.json": {
419
579
  "type": "security_notice",
420
580
  "event_id": "7217400317439950009",
@@ -429,7 +589,17 @@
429
589
  "chat_id": "42",
430
590
  "data": {
431
591
  "user_id": "1002",
432
- "is_typing": true
592
+ "is_typing": true,
593
+ "action": "recording_voice"
594
+ }
595
+ },
596
+ "server/user_updated.json": {
597
+ "type": "user_updated",
598
+ "event_id": "7217400317439950012",
599
+ "chat_id": null,
600
+ "data": {
601
+ "user_id": "7",
602
+ "profile_version": 3
433
603
  }
434
604
  }
435
605
  }