@bruch/max-client 0.1.0

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.
Files changed (174) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +168 -0
  3. package/UPSTREAM.md +10 -0
  4. package/dist/api/account.d.ts +24 -0
  5. package/dist/api/account.d.ts.map +1 -0
  6. package/dist/api/auth.d.ts +57 -0
  7. package/dist/api/auth.d.ts.map +1 -0
  8. package/dist/api/bots.d.ts +8 -0
  9. package/dist/api/bots.d.ts.map +1 -0
  10. package/dist/api/chats.d.ts +41 -0
  11. package/dist/api/chats.d.ts.map +1 -0
  12. package/dist/api/facade.d.ts +19 -0
  13. package/dist/api/facade.d.ts.map +1 -0
  14. package/dist/api/index.d.ts +10 -0
  15. package/dist/api/index.d.ts.map +1 -0
  16. package/dist/api/messages.d.ts +35 -0
  17. package/dist/api/messages.d.ts.map +1 -0
  18. package/dist/api/response.d.ts +7 -0
  19. package/dist/api/response.d.ts.map +1 -0
  20. package/dist/api/runtime.d.ts +19 -0
  21. package/dist/api/runtime.d.ts.map +1 -0
  22. package/dist/api/uploads.d.ts +23 -0
  23. package/dist/api/uploads.d.ts.map +1 -0
  24. package/dist/api/users.d.ts +25 -0
  25. package/dist/api/users.d.ts.map +1 -0
  26. package/dist/app.d.ts +55 -0
  27. package/dist/app.d.ts.map +1 -0
  28. package/dist/auth/flows.d.ts +27 -0
  29. package/dist/auth/flows.d.ts.map +1 -0
  30. package/dist/auth/index.d.ts +3 -0
  31. package/dist/auth/index.d.ts.map +1 -0
  32. package/dist/auth/index.js +109 -0
  33. package/dist/auth/index.js.map +11 -0
  34. package/dist/auth/providers.d.ts +11 -0
  35. package/dist/auth/providers.d.ts.map +1 -0
  36. package/dist/client.d.ts +139 -0
  37. package/dist/client.d.ts.map +1 -0
  38. package/dist/config.d.ts +80 -0
  39. package/dist/config.d.ts.map +1 -0
  40. package/dist/connection/connection.d.ts +25 -0
  41. package/dist/connection/connection.d.ts.map +1 -0
  42. package/dist/connection/index.d.ts +4 -0
  43. package/dist/connection/index.d.ts.map +1 -0
  44. package/dist/connection/pending.d.ts +9 -0
  45. package/dist/connection/pending.d.ts.map +1 -0
  46. package/dist/connection/readers.d.ts +17 -0
  47. package/dist/connection/readers.d.ts.map +1 -0
  48. package/dist/dispatch/dispatcher.d.ts +16 -0
  49. package/dist/dispatch/dispatcher.d.ts.map +1 -0
  50. package/dist/dispatch/index.d.ts +3 -0
  51. package/dist/dispatch/index.d.ts.map +1 -0
  52. package/dist/dispatch/router.d.ts +64 -0
  53. package/dist/dispatch/router.d.ts.map +1 -0
  54. package/dist/errors.d.ts +24 -0
  55. package/dist/errors.d.ts.map +1 -0
  56. package/dist/files/file.d.ts +29 -0
  57. package/dist/files/file.d.ts.map +1 -0
  58. package/dist/files/index.d.ts +2 -0
  59. package/dist/files/index.d.ts.map +1 -0
  60. package/dist/files/index.js +95 -0
  61. package/dist/files/index.js.map +10 -0
  62. package/dist/formatting/index.d.ts +2 -0
  63. package/dist/formatting/index.d.ts.map +1 -0
  64. package/dist/formatting/markdown.d.ts +13 -0
  65. package/dist/formatting/markdown.d.ts.map +1 -0
  66. package/dist/index.d.ts +15 -0
  67. package/dist/index.d.ts.map +1 -0
  68. package/dist/index.js +3967 -0
  69. package/dist/index.js.map +48 -0
  70. package/dist/logging.d.ts +10 -0
  71. package/dist/logging.d.ts.map +1 -0
  72. package/dist/protocol/compression.d.ts +8 -0
  73. package/dist/protocol/compression.d.ts.map +1 -0
  74. package/dist/protocol/enums.d.ts +175 -0
  75. package/dist/protocol/enums.d.ts.map +1 -0
  76. package/dist/protocol/index.d.ts +6 -0
  77. package/dist/protocol/index.d.ts.map +1 -0
  78. package/dist/protocol/index.js +438 -0
  79. package/dist/protocol/index.js.map +13 -0
  80. package/dist/protocol/tcp.d.ts +35 -0
  81. package/dist/protocol/tcp.d.ts.map +1 -0
  82. package/dist/protocol/types.d.ts +38 -0
  83. package/dist/protocol/types.d.ts.map +1 -0
  84. package/dist/protocol/websocket.d.ts +7 -0
  85. package/dist/protocol/websocket.d.ts.map +1 -0
  86. package/dist/session/index.d.ts +3 -0
  87. package/dist/session/index.d.ts.map +1 -0
  88. package/dist/session/index.js +179 -0
  89. package/dist/session/index.js.map +12 -0
  90. package/dist/session/store.d.ts +18 -0
  91. package/dist/session/store.d.ts.map +1 -0
  92. package/dist/session/types.d.ts +29 -0
  93. package/dist/session/types.d.ts.map +1 -0
  94. package/dist/telemetry/index.d.ts +4 -0
  95. package/dist/telemetry/index.d.ts.map +1 -0
  96. package/dist/telemetry/index.js +831 -0
  97. package/dist/telemetry/index.js.map +17 -0
  98. package/dist/telemetry/navigation.d.ts +41 -0
  99. package/dist/telemetry/navigation.d.ts.map +1 -0
  100. package/dist/telemetry/payloads.d.ts +30 -0
  101. package/dist/telemetry/payloads.d.ts.map +1 -0
  102. package/dist/telemetry/service.d.ts +53 -0
  103. package/dist/telemetry/service.d.ts.map +1 -0
  104. package/dist/transport/base.d.ts +18 -0
  105. package/dist/transport/base.d.ts.map +1 -0
  106. package/dist/transport/index.d.ts +4 -0
  107. package/dist/transport/index.d.ts.map +1 -0
  108. package/dist/transport/tcp.d.ts +28 -0
  109. package/dist/transport/tcp.d.ts.map +1 -0
  110. package/dist/transport/websocket.d.ts +14 -0
  111. package/dist/transport/websocket.d.ts.map +1 -0
  112. package/dist/types/attachments.d.ts +18 -0
  113. package/dist/types/attachments.d.ts.map +1 -0
  114. package/dist/types/index.d.ts +4 -0
  115. package/dist/types/index.d.ts.map +1 -0
  116. package/dist/types/index.js +376 -0
  117. package/dist/types/index.js.map +12 -0
  118. package/dist/types/models.d.ts +210 -0
  119. package/dist/types/models.d.ts.map +1 -0
  120. package/dist/types/utils.d.ts +10 -0
  121. package/dist/types/utils.d.ts.map +1 -0
  122. package/package.json +95 -0
  123. package/src/api/account.ts +93 -0
  124. package/src/api/auth.ts +312 -0
  125. package/src/api/bots.ts +21 -0
  126. package/src/api/chats.ts +234 -0
  127. package/src/api/facade.ts +28 -0
  128. package/src/api/index.ts +9 -0
  129. package/src/api/messages.ts +230 -0
  130. package/src/api/response.ts +24 -0
  131. package/src/api/runtime.ts +27 -0
  132. package/src/api/uploads.ts +91 -0
  133. package/src/api/users.ts +68 -0
  134. package/src/app.ts +271 -0
  135. package/src/auth/flows.ts +103 -0
  136. package/src/auth/index.ts +2 -0
  137. package/src/auth/providers.ts +30 -0
  138. package/src/client.ts +506 -0
  139. package/src/config.ts +161 -0
  140. package/src/connection/connection.ts +93 -0
  141. package/src/connection/index.ts +3 -0
  142. package/src/connection/pending.ts +49 -0
  143. package/src/connection/readers.ts +33 -0
  144. package/src/dispatch/dispatcher.ts +194 -0
  145. package/src/dispatch/index.ts +2 -0
  146. package/src/dispatch/router.ts +149 -0
  147. package/src/errors.ts +41 -0
  148. package/src/files/file.ts +92 -0
  149. package/src/files/index.ts +1 -0
  150. package/src/formatting/index.ts +1 -0
  151. package/src/formatting/markdown.ts +123 -0
  152. package/src/index.ts +15 -0
  153. package/src/logging.ts +67 -0
  154. package/src/protocol/compression.ts +69 -0
  155. package/src/protocol/enums.ts +175 -0
  156. package/src/protocol/index.ts +5 -0
  157. package/src/protocol/tcp.ts +139 -0
  158. package/src/protocol/types.ts +45 -0
  159. package/src/protocol/websocket.ts +47 -0
  160. package/src/session/index.ts +2 -0
  161. package/src/session/store.ts +154 -0
  162. package/src/session/types.ts +45 -0
  163. package/src/telemetry/index.ts +3 -0
  164. package/src/telemetry/navigation.ts +160 -0
  165. package/src/telemetry/payloads.ts +84 -0
  166. package/src/telemetry/service.ts +194 -0
  167. package/src/transport/base.ts +43 -0
  168. package/src/transport/index.ts +3 -0
  169. package/src/transport/tcp.ts +296 -0
  170. package/src/transport/websocket.ts +63 -0
  171. package/src/types/attachments.ts +24 -0
  172. package/src/types/index.ts +3 -0
  173. package/src/types/models.ts +461 -0
  174. package/src/types/utils.ts +45 -0
@@ -0,0 +1,10 @@
1
+ export type LogLevel = "DEBUG" | "INFO" | "WARN" | "ERROR" | "SILENT";
2
+ export interface Logger {
3
+ debug(message: string, context?: Record<string, unknown>): void;
4
+ info(message: string, context?: Record<string, unknown>): void;
5
+ warn(message: string, context?: Record<string, unknown>): void;
6
+ error(message: string, context?: Record<string, unknown>): void;
7
+ }
8
+ export declare function configureLogging(level?: LogLevel, logger?: Logger): Logger;
9
+ export declare function getLogger(): Logger;
10
+ //# sourceMappingURL=logging.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logging.d.ts","sourceRoot":"","sources":["../src/logging.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEtE,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAChE,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC/D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC/D,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CACjE;AA0CD,wBAAgB,gBAAgB,CAAC,KAAK,GAAE,QAAiB,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAGlF;AAED,wBAAgB,SAAS,IAAI,MAAM,CAElC"}
@@ -0,0 +1,8 @@
1
+ export declare class Lz4BlockCompression {
2
+ decompress(source: Uint8Array, maxOutput?: number): Uint8Array;
3
+ private ensureSize;
4
+ }
5
+ export declare class ZstdCompression {
6
+ decompress(source: Uint8Array, maxOutput?: number): Uint8Array;
7
+ }
8
+ //# sourceMappingURL=compression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compression.d.ts","sourceRoot":"","sources":["../../src/protocol/compression.ts"],"names":[],"mappings":"AAEA,qBAAa,mBAAmB;IAC9B,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,SAAqB,GAAG,UAAU;IAsD1E,OAAO,CAAC,UAAU;CAGnB;AAED,qBAAa,eAAe;IAC1B,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,SAAqB,GAAG,UAAU;CAK3E"}
@@ -0,0 +1,175 @@
1
+ export declare const Command: {
2
+ readonly REQUEST: 0;
3
+ readonly RESPONSE: 1;
4
+ readonly EVENT: 2;
5
+ readonly ERROR: 3;
6
+ };
7
+ export type Command = (typeof Command)[keyof typeof Command];
8
+ export declare const Opcode: {
9
+ readonly PING: 1;
10
+ readonly DEBUG: 2;
11
+ readonly RECONNECT: 3;
12
+ readonly LOG: 5;
13
+ readonly SESSION_INIT: 6;
14
+ readonly PROFILE: 16;
15
+ readonly AUTH_REQUEST: 17;
16
+ readonly AUTH: 18;
17
+ readonly LOGIN: 19;
18
+ readonly LOGOUT: 20;
19
+ readonly SYNC: 21;
20
+ readonly CONFIG: 22;
21
+ readonly AUTH_CONFIRM: 23;
22
+ readonly PRESET_AVATARS: 25;
23
+ readonly ASSETS_GET: 26;
24
+ readonly ASSETS_UPDATE: 27;
25
+ readonly ASSETS_GET_BY_IDS: 28;
26
+ readonly ASSETS_ADD: 29;
27
+ readonly SEARCH_FEEDBACK: 31;
28
+ readonly CONTACT_INFO: 32;
29
+ readonly CONTACT_ADD: 33;
30
+ readonly CONTACT_UPDATE: 34;
31
+ readonly CONTACT_PRESENCE: 35;
32
+ readonly CONTACT_LIST: 36;
33
+ readonly CONTACT_SEARCH: 37;
34
+ readonly CONTACT_MUTUAL: 38;
35
+ readonly CONTACT_PHOTOS: 39;
36
+ readonly CONTACT_SORT: 40;
37
+ readonly CONTACT_VERIFY: 42;
38
+ readonly REMOVE_CONTACT_PHOTO: 43;
39
+ readonly CONTACT_INFO_BY_PHONE: 46;
40
+ readonly CHAT_INFO: 48;
41
+ readonly CHAT_HISTORY: 49;
42
+ readonly CHAT_MARK: 50;
43
+ readonly CHAT_MEDIA: 51;
44
+ readonly CHAT_DELETE: 52;
45
+ readonly CHATS_LIST: 53;
46
+ readonly CHAT_CLEAR: 54;
47
+ readonly CHAT_UPDATE: 55;
48
+ readonly CHAT_CHECK_LINK: 56;
49
+ readonly CHAT_JOIN: 57;
50
+ readonly CHAT_LEAVE: 58;
51
+ readonly CHAT_MEMBERS: 59;
52
+ readonly PUBLIC_SEARCH: 60;
53
+ readonly CHAT_PERSONAL_CONFIG: 61;
54
+ readonly CHAT_LIVESTREAM_INFO: 62;
55
+ readonly CHAT_CREATE: 63;
56
+ readonly MSG_SEND: 64;
57
+ readonly MSG_TYPING: 65;
58
+ readonly MSG_DELETE: 66;
59
+ readonly MSG_EDIT: 67;
60
+ readonly CHAT_SEARCH: 68;
61
+ readonly MSG_SHARE_PREVIEW: 70;
62
+ readonly MSG_GET: 71;
63
+ readonly MSG_SEARCH_TOUCH: 72;
64
+ readonly MSG_SEARCH: 73;
65
+ readonly MSG_GET_STAT: 74;
66
+ readonly CHAT_SUBSCRIBE: 75;
67
+ readonly VIDEO_CHAT_START: 76;
68
+ readonly CHAT_MEMBERS_UPDATE: 77;
69
+ readonly VIDEO_CHAT_START_ACTIVE: 78;
70
+ readonly VIDEO_CHAT_HISTORY: 79;
71
+ readonly PHOTO_UPLOAD: 80;
72
+ readonly STICKER_UPLOAD: 81;
73
+ readonly VIDEO_UPLOAD: 82;
74
+ readonly VIDEO_PLAY: 83;
75
+ readonly VIDEO_CHAT_CREATE_JOIN_LINK: 84;
76
+ readonly CHAT_PIN_SET_VISIBILITY: 86;
77
+ readonly FILE_UPLOAD: 87;
78
+ readonly FILE_DOWNLOAD: 88;
79
+ readonly LINK_INFO: 89;
80
+ readonly MSG_DELETE_RANGE: 92;
81
+ readonly SESSIONS_INFO: 96;
82
+ readonly SESSIONS_CLOSE: 97;
83
+ readonly PHONE_BIND_REQUEST: 98;
84
+ readonly PHONE_BIND_CONFIRM: 99;
85
+ readonly AUTH_LOGIN_RESTORE_PASSWORD: 101;
86
+ readonly GET_INBOUND_CALLS: 103;
87
+ readonly AUTH_2FA_DETAILS: 104;
88
+ readonly EXTERNAL_CALLBACK: 105;
89
+ readonly AUTH_VALIDATE_PASSWORD: 107;
90
+ readonly AUTH_VALIDATE_HINT: 108;
91
+ readonly AUTH_VERIFY_EMAIL: 109;
92
+ readonly AUTH_CHECK_EMAIL: 110;
93
+ readonly AUTH_SET_2FA: 111;
94
+ readonly AUTH_CREATE_TRACK: 112;
95
+ readonly AUTH_CHECK_PASSWORD: 113;
96
+ readonly AUTH_LOGIN_CHECK_PASSWORD: 115;
97
+ readonly AUTH_LOGIN_PROFILE_DELETE: 116;
98
+ readonly CHAT_COMPLAIN: 117;
99
+ readonly MSG_SEND_CALLBACK: 118;
100
+ readonly SUSPEND_BOT: 119;
101
+ readonly LOCATION_STOP: 124;
102
+ readonly LOCATION_SEND: 125;
103
+ readonly LOCATION_REQUEST: 126;
104
+ readonly GET_LAST_MENTIONS: 127;
105
+ readonly NOTIF_MESSAGE: 128;
106
+ readonly NOTIF_TYPING: 129;
107
+ readonly NOTIF_MARK: 130;
108
+ readonly NOTIF_CONTACT: 131;
109
+ readonly NOTIF_PRESENCE: 132;
110
+ readonly NOTIF_CONFIG: 134;
111
+ readonly NOTIF_CHAT: 135;
112
+ readonly NOTIF_ATTACH: 136;
113
+ readonly NOTIF_CALL_START: 137;
114
+ readonly NOTIF_CONTACT_SORT: 139;
115
+ readonly NOTIF_MSG_DELETE_RANGE: 140;
116
+ readonly NOTIF_MSG_DELETE: 142;
117
+ readonly NOTIF_CALLBACK_ANSWER: 143;
118
+ readonly CHAT_BOT_COMMANDS: 144;
119
+ readonly BOT_INFO: 145;
120
+ readonly NOTIF_LOCATION: 147;
121
+ readonly NOTIF_LOCATION_REQUEST: 148;
122
+ readonly NOTIF_ASSETS_UPDATE: 150;
123
+ readonly NOTIF_DRAFT: 152;
124
+ readonly NOTIF_DRAFT_DISCARD: 153;
125
+ readonly NOTIF_MSG_DELAYED: 154;
126
+ readonly NOTIF_MSG_REACTIONS_CHANGED: 155;
127
+ readonly NOTIF_MSG_YOU_REACTED: 156;
128
+ readonly CALLS_TOKEN: 158;
129
+ readonly NOTIF_PROFILE: 159;
130
+ readonly WEB_APP_INIT_DATA: 160;
131
+ readonly COMPLAIN: 161;
132
+ readonly COMPLAIN_REASONS_GET: 162;
133
+ readonly VIDEO_CHAT_JOIN: 166;
134
+ readonly DRAFT_SAVE: 176;
135
+ readonly DRAFT_DISCARD: 177;
136
+ readonly MSG_REACTION: 178;
137
+ readonly MSG_CANCEL_REACTION: 179;
138
+ readonly MSG_GET_REACTIONS: 180;
139
+ readonly MSG_GET_DETAILED_REACTIONS: 181;
140
+ readonly STICKER_CREATE: 193;
141
+ readonly STICKER_SUGGEST: 194;
142
+ readonly VIDEO_CHAT_MEMBERS: 195;
143
+ readonly CHAT_HIDE: 196;
144
+ readonly CHAT_SEARCH_COMMON_PARTICIPANTS: 198;
145
+ readonly PROFILE_DELETE: 199;
146
+ readonly PROFILE_DELETE_TIME: 200;
147
+ readonly TRANSCRIBE_MEDIA: 202;
148
+ readonly ORG_INFO: 256;
149
+ readonly CHAT_REACTIONS_SETTINGS_SET: 257;
150
+ readonly REACTIONS_SETTINGS_GET_BY_CHAT_ID: 258;
151
+ readonly ASSETS_REMOVE: 259;
152
+ readonly ASSETS_MOVE: 260;
153
+ readonly ASSETS_LIST_MODIFY: 261;
154
+ readonly FOLDERS_GET: 272;
155
+ readonly FOLDERS_GET_BY_ID: 273;
156
+ readonly FOLDERS_UPDATE: 274;
157
+ readonly FOLDERS_REORDER: 275;
158
+ readonly FOLDERS_DELETE: 276;
159
+ readonly NOTIF_FOLDERS: 277;
160
+ readonly GET_QR: 288;
161
+ readonly GET_QR_STATUS: 289;
162
+ readonly AUTH_QR_APPROVE: 290;
163
+ readonly LOGIN_BY_QR: 291;
164
+ readonly NOTIF_BANNERS: 292;
165
+ readonly NOTIF_TRANSCRIPTION: 293;
166
+ readonly CHAT_SUGGEST: 300;
167
+ readonly AUDIO_PLAY: 301;
168
+ readonly BANNERS_GET: 302;
169
+ readonly MSG_DELIVERY: 303;
170
+ readonly SEND_VOTE: 304;
171
+ readonly VOTERS_LIST_BY_ANSWER: 305;
172
+ readonly GET_POLL_UPDATES: 306;
173
+ };
174
+ export type Opcode = (typeof Opcode)[keyof typeof Opcode];
175
+ //# sourceMappingURL=enums.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../../src/protocol/enums.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO;;;;;CAKV,CAAC;AACX,MAAM,MAAM,OAAO,GAAG,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,OAAO,OAAO,CAAC,CAAC;AAE7D,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqKT,CAAC;AACX,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from "./compression.ts";
2
+ export * from "./enums.ts";
3
+ export * from "./tcp.ts";
4
+ export * from "./types.ts";
5
+ export * from "./websocket.ts";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/protocol/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,438 @@
1
+ // @bun
2
+ // src/protocol/compression.ts
3
+ var DEFAULT_MAX_OUTPUT = 5 * 1024 * 1024;
4
+
5
+ class Lz4BlockCompression {
6
+ decompress(source, maxOutput = DEFAULT_MAX_OUTPUT) {
7
+ const output = [];
8
+ let position = 0;
9
+ while (position < source.length) {
10
+ const token = source[position++];
11
+ if (token === undefined)
12
+ break;
13
+ let literalLength = token >>> 4;
14
+ if (literalLength === 15) {
15
+ while (position < source.length) {
16
+ const byte = source[position++];
17
+ if (byte === undefined)
18
+ break;
19
+ literalLength += byte;
20
+ if (byte !== 255)
21
+ break;
22
+ }
23
+ }
24
+ if (position + literalLength > source.length) {
25
+ throw new RangeError("LZ4: literal length out of bounds");
26
+ }
27
+ for (let index = 0;index < literalLength; index += 1) {
28
+ output.push(source[position + index]);
29
+ }
30
+ position += literalLength;
31
+ this.ensureSize(output.length, maxOutput);
32
+ if (position >= source.length)
33
+ break;
34
+ if (position + 1 >= source.length)
35
+ throw new RangeError("LZ4: incomplete offset");
36
+ const offset = source[position] | source[position + 1] << 8;
37
+ position += 2;
38
+ if (offset === 0)
39
+ throw new RangeError("LZ4: zero offset");
40
+ let matchLength = (token & 15) + 4;
41
+ if ((token & 15) === 15) {
42
+ while (position < source.length) {
43
+ const byte = source[position++];
44
+ if (byte === undefined)
45
+ break;
46
+ matchLength += byte;
47
+ if (byte !== 255)
48
+ break;
49
+ }
50
+ }
51
+ const matchPosition = output.length - offset;
52
+ if (matchPosition < 0)
53
+ throw new RangeError("LZ4: match out of bounds");
54
+ for (let index = 0;index < matchLength; index += 1) {
55
+ output.push(output[matchPosition + index % offset]);
56
+ }
57
+ this.ensureSize(output.length, maxOutput);
58
+ }
59
+ return Uint8Array.from(output);
60
+ }
61
+ ensureSize(size, maximum) {
62
+ if (size > maximum)
63
+ throw new RangeError("LZ4: output too large");
64
+ }
65
+ }
66
+
67
+ class ZstdCompression {
68
+ decompress(source, maxOutput = DEFAULT_MAX_OUTPUT) {
69
+ const output = Bun.zstdDecompressSync(source);
70
+ if (output.byteLength > maxOutput)
71
+ throw new RangeError("Zstd: output too large");
72
+ return output;
73
+ }
74
+ }
75
+ // src/protocol/enums.ts
76
+ var Command = {
77
+ REQUEST: 0,
78
+ RESPONSE: 1,
79
+ EVENT: 2,
80
+ ERROR: 3
81
+ };
82
+ var Opcode = {
83
+ PING: 1,
84
+ DEBUG: 2,
85
+ RECONNECT: 3,
86
+ LOG: 5,
87
+ SESSION_INIT: 6,
88
+ PROFILE: 16,
89
+ AUTH_REQUEST: 17,
90
+ AUTH: 18,
91
+ LOGIN: 19,
92
+ LOGOUT: 20,
93
+ SYNC: 21,
94
+ CONFIG: 22,
95
+ AUTH_CONFIRM: 23,
96
+ PRESET_AVATARS: 25,
97
+ ASSETS_GET: 26,
98
+ ASSETS_UPDATE: 27,
99
+ ASSETS_GET_BY_IDS: 28,
100
+ ASSETS_ADD: 29,
101
+ SEARCH_FEEDBACK: 31,
102
+ CONTACT_INFO: 32,
103
+ CONTACT_ADD: 33,
104
+ CONTACT_UPDATE: 34,
105
+ CONTACT_PRESENCE: 35,
106
+ CONTACT_LIST: 36,
107
+ CONTACT_SEARCH: 37,
108
+ CONTACT_MUTUAL: 38,
109
+ CONTACT_PHOTOS: 39,
110
+ CONTACT_SORT: 40,
111
+ CONTACT_VERIFY: 42,
112
+ REMOVE_CONTACT_PHOTO: 43,
113
+ CONTACT_INFO_BY_PHONE: 46,
114
+ CHAT_INFO: 48,
115
+ CHAT_HISTORY: 49,
116
+ CHAT_MARK: 50,
117
+ CHAT_MEDIA: 51,
118
+ CHAT_DELETE: 52,
119
+ CHATS_LIST: 53,
120
+ CHAT_CLEAR: 54,
121
+ CHAT_UPDATE: 55,
122
+ CHAT_CHECK_LINK: 56,
123
+ CHAT_JOIN: 57,
124
+ CHAT_LEAVE: 58,
125
+ CHAT_MEMBERS: 59,
126
+ PUBLIC_SEARCH: 60,
127
+ CHAT_PERSONAL_CONFIG: 61,
128
+ CHAT_LIVESTREAM_INFO: 62,
129
+ CHAT_CREATE: 63,
130
+ MSG_SEND: 64,
131
+ MSG_TYPING: 65,
132
+ MSG_DELETE: 66,
133
+ MSG_EDIT: 67,
134
+ CHAT_SEARCH: 68,
135
+ MSG_SHARE_PREVIEW: 70,
136
+ MSG_GET: 71,
137
+ MSG_SEARCH_TOUCH: 72,
138
+ MSG_SEARCH: 73,
139
+ MSG_GET_STAT: 74,
140
+ CHAT_SUBSCRIBE: 75,
141
+ VIDEO_CHAT_START: 76,
142
+ CHAT_MEMBERS_UPDATE: 77,
143
+ VIDEO_CHAT_START_ACTIVE: 78,
144
+ VIDEO_CHAT_HISTORY: 79,
145
+ PHOTO_UPLOAD: 80,
146
+ STICKER_UPLOAD: 81,
147
+ VIDEO_UPLOAD: 82,
148
+ VIDEO_PLAY: 83,
149
+ VIDEO_CHAT_CREATE_JOIN_LINK: 84,
150
+ CHAT_PIN_SET_VISIBILITY: 86,
151
+ FILE_UPLOAD: 87,
152
+ FILE_DOWNLOAD: 88,
153
+ LINK_INFO: 89,
154
+ MSG_DELETE_RANGE: 92,
155
+ SESSIONS_INFO: 96,
156
+ SESSIONS_CLOSE: 97,
157
+ PHONE_BIND_REQUEST: 98,
158
+ PHONE_BIND_CONFIRM: 99,
159
+ AUTH_LOGIN_RESTORE_PASSWORD: 101,
160
+ GET_INBOUND_CALLS: 103,
161
+ AUTH_2FA_DETAILS: 104,
162
+ EXTERNAL_CALLBACK: 105,
163
+ AUTH_VALIDATE_PASSWORD: 107,
164
+ AUTH_VALIDATE_HINT: 108,
165
+ AUTH_VERIFY_EMAIL: 109,
166
+ AUTH_CHECK_EMAIL: 110,
167
+ AUTH_SET_2FA: 111,
168
+ AUTH_CREATE_TRACK: 112,
169
+ AUTH_CHECK_PASSWORD: 113,
170
+ AUTH_LOGIN_CHECK_PASSWORD: 115,
171
+ AUTH_LOGIN_PROFILE_DELETE: 116,
172
+ CHAT_COMPLAIN: 117,
173
+ MSG_SEND_CALLBACK: 118,
174
+ SUSPEND_BOT: 119,
175
+ LOCATION_STOP: 124,
176
+ LOCATION_SEND: 125,
177
+ LOCATION_REQUEST: 126,
178
+ GET_LAST_MENTIONS: 127,
179
+ NOTIF_MESSAGE: 128,
180
+ NOTIF_TYPING: 129,
181
+ NOTIF_MARK: 130,
182
+ NOTIF_CONTACT: 131,
183
+ NOTIF_PRESENCE: 132,
184
+ NOTIF_CONFIG: 134,
185
+ NOTIF_CHAT: 135,
186
+ NOTIF_ATTACH: 136,
187
+ NOTIF_CALL_START: 137,
188
+ NOTIF_CONTACT_SORT: 139,
189
+ NOTIF_MSG_DELETE_RANGE: 140,
190
+ NOTIF_MSG_DELETE: 142,
191
+ NOTIF_CALLBACK_ANSWER: 143,
192
+ CHAT_BOT_COMMANDS: 144,
193
+ BOT_INFO: 145,
194
+ NOTIF_LOCATION: 147,
195
+ NOTIF_LOCATION_REQUEST: 148,
196
+ NOTIF_ASSETS_UPDATE: 150,
197
+ NOTIF_DRAFT: 152,
198
+ NOTIF_DRAFT_DISCARD: 153,
199
+ NOTIF_MSG_DELAYED: 154,
200
+ NOTIF_MSG_REACTIONS_CHANGED: 155,
201
+ NOTIF_MSG_YOU_REACTED: 156,
202
+ CALLS_TOKEN: 158,
203
+ NOTIF_PROFILE: 159,
204
+ WEB_APP_INIT_DATA: 160,
205
+ COMPLAIN: 161,
206
+ COMPLAIN_REASONS_GET: 162,
207
+ VIDEO_CHAT_JOIN: 166,
208
+ DRAFT_SAVE: 176,
209
+ DRAFT_DISCARD: 177,
210
+ MSG_REACTION: 178,
211
+ MSG_CANCEL_REACTION: 179,
212
+ MSG_GET_REACTIONS: 180,
213
+ MSG_GET_DETAILED_REACTIONS: 181,
214
+ STICKER_CREATE: 193,
215
+ STICKER_SUGGEST: 194,
216
+ VIDEO_CHAT_MEMBERS: 195,
217
+ CHAT_HIDE: 196,
218
+ CHAT_SEARCH_COMMON_PARTICIPANTS: 198,
219
+ PROFILE_DELETE: 199,
220
+ PROFILE_DELETE_TIME: 200,
221
+ TRANSCRIBE_MEDIA: 202,
222
+ ORG_INFO: 256,
223
+ CHAT_REACTIONS_SETTINGS_SET: 257,
224
+ REACTIONS_SETTINGS_GET_BY_CHAT_ID: 258,
225
+ ASSETS_REMOVE: 259,
226
+ ASSETS_MOVE: 260,
227
+ ASSETS_LIST_MODIFY: 261,
228
+ FOLDERS_GET: 272,
229
+ FOLDERS_GET_BY_ID: 273,
230
+ FOLDERS_UPDATE: 274,
231
+ FOLDERS_REORDER: 275,
232
+ FOLDERS_DELETE: 276,
233
+ NOTIF_FOLDERS: 277,
234
+ GET_QR: 288,
235
+ GET_QR_STATUS: 289,
236
+ AUTH_QR_APPROVE: 290,
237
+ LOGIN_BY_QR: 291,
238
+ NOTIF_BANNERS: 292,
239
+ NOTIF_TRANSCRIPTION: 293,
240
+ CHAT_SUGGEST: 300,
241
+ AUDIO_PLAY: 301,
242
+ BANNERS_GET: 302,
243
+ MSG_DELIVERY: 303,
244
+ SEND_VOTE: 304,
245
+ VOTERS_LIST_BY_ANSWER: 305,
246
+ GET_POLL_UPDATES: 306
247
+ };
248
+ // src/protocol/tcp.ts
249
+ import { decode, encode } from "@msgpack/msgpack";
250
+ var TCP_HEADER_SIZE = 10;
251
+
252
+ class TcpPacketFramer {
253
+ pack(options) {
254
+ if (options.payloadBytes.byteLength > 16777215) {
255
+ throw new RangeError("TCP payload exceeds the 24-bit length field");
256
+ }
257
+ const result = new Uint8Array(TCP_HEADER_SIZE + options.payloadBytes.byteLength);
258
+ const view = new DataView(result.buffer);
259
+ view.setUint8(0, options.ver);
260
+ view.setUint8(1, options.cmd);
261
+ view.setUint16(2, options.seq, false);
262
+ view.setUint16(4, options.opcode, false);
263
+ const packedLength = (options.flags & 255) << 24 | options.payloadBytes.byteLength;
264
+ view.setUint32(6, packedLength >>> 0, false);
265
+ result.set(options.payloadBytes, TCP_HEADER_SIZE);
266
+ return result;
267
+ }
268
+ unpack(data) {
269
+ if (data.byteLength < TCP_HEADER_SIZE)
270
+ return null;
271
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
272
+ const packedLength = view.getUint32(6, false);
273
+ const payloadLength = packedLength & 16777215;
274
+ if (data.byteLength < TCP_HEADER_SIZE + payloadLength)
275
+ return null;
276
+ return {
277
+ header: {
278
+ ver: view.getUint8(0),
279
+ cmd: view.getUint8(1),
280
+ seq: view.getUint16(2, false),
281
+ opcode: view.getUint16(4, false),
282
+ flags: packedLength >>> 24,
283
+ payloadLength
284
+ },
285
+ payloadBytes: data.slice(TCP_HEADER_SIZE, TCP_HEADER_SIZE + payloadLength)
286
+ };
287
+ }
288
+ unpackPayloadLength(data) {
289
+ if (data.byteLength < TCP_HEADER_SIZE)
290
+ return null;
291
+ return new DataView(data.buffer, data.byteOffset, data.byteLength).getUint32(6, false) & 16777215;
292
+ }
293
+ }
294
+
295
+ class MsgpackPayloadCodec {
296
+ encode(payload) {
297
+ if (payload === null || payload === undefined)
298
+ return new Uint8Array;
299
+ return encode(payload, { useBigInt64: true, ignoreUndefined: true });
300
+ }
301
+ decode(payload) {
302
+ if (payload.byteLength === 0)
303
+ return {};
304
+ return normalizeKeys(decode(payload, { useBigInt64: true }));
305
+ }
306
+ }
307
+
308
+ class TcpPayloadDecoder {
309
+ serializer;
310
+ lz4;
311
+ zstd;
312
+ constructor(serializer = new MsgpackPayloadCodec, lz4 = new Lz4BlockCompression, zstd = new ZstdCompression) {
313
+ this.serializer = serializer;
314
+ this.lz4 = lz4;
315
+ this.zstd = zstd;
316
+ }
317
+ decode(payload, flags = 0) {
318
+ if (payload.byteLength === 0)
319
+ return {};
320
+ let decoded = payload;
321
+ if (flags === 255)
322
+ decoded = this.zstd.decompress(payload);
323
+ else if (flags > 127)
324
+ throw new RangeError(`Invalid TCP compression factor: ${flags}`);
325
+ else if (flags > 0)
326
+ decoded = this.lz4.decompress(payload);
327
+ return this.serializer.decode(decoded);
328
+ }
329
+ }
330
+
331
+ class TcpProtocol {
332
+ version = 10;
333
+ framer = new TcpPacketFramer;
334
+ serializer = new MsgpackPayloadCodec;
335
+ payloadDecoder = new TcpPayloadDecoder(this.serializer);
336
+ encode(frame) {
337
+ const payloadBytes = this.serializer.encode(frame.payload);
338
+ return this.framer.pack({
339
+ ver: this.version,
340
+ cmd: frame.cmd ?? 0,
341
+ seq: frame.seq,
342
+ opcode: frame.opcode,
343
+ flags: 0,
344
+ payloadBytes
345
+ });
346
+ }
347
+ decode(raw) {
348
+ const packet = this.framer.unpack(raw);
349
+ if (!packet)
350
+ return { opcode: 0, cmd: 0, seq: null, payload: null, raw: null };
351
+ const payload = this.payloadDecoder.decode(packet.payloadBytes, packet.header.flags);
352
+ return {
353
+ opcode: packet.header.opcode,
354
+ cmd: packet.header.cmd,
355
+ seq: packet.header.seq,
356
+ payload,
357
+ raw: payload
358
+ };
359
+ }
360
+ }
361
+ function normalizeKeys(value) {
362
+ if (Array.isArray(value))
363
+ return value.map(normalizeKeys);
364
+ if (value instanceof Map) {
365
+ const result = Object.create(null);
366
+ for (const [key, item] of value)
367
+ result[normalizeKey(key)] = normalizeKeys(item);
368
+ return result;
369
+ }
370
+ if (value !== null && typeof value === "object" && !(value instanceof Uint8Array)) {
371
+ const result = Object.create(null);
372
+ for (const [key, item] of Object.entries(value))
373
+ result[normalizeKey(key)] = normalizeKeys(item);
374
+ return result;
375
+ }
376
+ return value;
377
+ }
378
+ function normalizeKey(value) {
379
+ if (value instanceof Uint8Array)
380
+ return new TextDecoder().decode(value);
381
+ return String(value);
382
+ }
383
+ // src/protocol/websocket.ts
384
+ import { isInteger, isSafeNumber, parse, stringify } from "lossless-json";
385
+
386
+ class WsProtocol {
387
+ version = 11;
388
+ encode(frame) {
389
+ return stringify({ ...frame, cmd: frame.cmd ?? 0, ver: this.version });
390
+ }
391
+ decode(raw) {
392
+ try {
393
+ const value = parse(raw, undefined, {
394
+ parseNumber: (text) => {
395
+ if (isInteger(text) && !isSafeNumber(text))
396
+ return BigInt(text);
397
+ return Number(text);
398
+ }
399
+ });
400
+ if (!isRecord(value))
401
+ return emptyFrame();
402
+ const opcode = safeHeaderNumber(value.opcode);
403
+ const cmd = safeHeaderNumber(value.cmd ?? 0);
404
+ const seq = value.seq === null || value.seq === undefined ? null : safeHeaderNumber(value.seq);
405
+ const payload = isRecord(value.payload) ? value.payload : null;
406
+ return { opcode, cmd, seq, payload, raw: payload };
407
+ } catch {
408
+ return emptyFrame();
409
+ }
410
+ }
411
+ }
412
+ function safeHeaderNumber(value) {
413
+ const result = typeof value === "bigint" ? Number(value) : value;
414
+ if (typeof result !== "number" || !Number.isSafeInteger(result)) {
415
+ throw new TypeError("Invalid WebSocket frame header");
416
+ }
417
+ return result;
418
+ }
419
+ function isRecord(value) {
420
+ return value !== null && typeof value === "object" && !Array.isArray(value);
421
+ }
422
+ function emptyFrame() {
423
+ return { opcode: 0, cmd: 0, seq: null, payload: null, raw: null };
424
+ }
425
+ export {
426
+ ZstdCompression,
427
+ WsProtocol,
428
+ TcpProtocol,
429
+ TcpPayloadDecoder,
430
+ TcpPacketFramer,
431
+ TCP_HEADER_SIZE,
432
+ Opcode,
433
+ MsgpackPayloadCodec,
434
+ Lz4BlockCompression,
435
+ Command
436
+ };
437
+
438
+ //# debugId=48D4D6DC5C20417D64756E2164756E21