@bruch/max-client 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -64
- package/package.json +2 -3
- package/UPSTREAM.md +0 -10
package/README.md
CHANGED
|
@@ -1,68 +1,69 @@
|
|
|
1
|
-
#
|
|
1
|
+
# MAX Client
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
SMS- и QR-аутентификацию, сообщения, чаты, контакты и вложения.
|
|
3
|
+
An unofficial Bun/TypeScript client for the internal MAX messenger API. It supports regular user
|
|
4
|
+
accounts, SMS and QR authentication, messages, chats, contacts, attachments, and live events.
|
|
6
5
|
|
|
7
|
-
>
|
|
8
|
-
>
|
|
6
|
+
> This is not an official MAX SDK. The internal protocol may change without notice. Use the project
|
|
7
|
+
> only with your own accounts and for workflows that comply with the service rules and applicable
|
|
8
|
+
> laws.
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Requirements
|
|
11
11
|
|
|
12
|
-
- Bun 1.3.0
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
- ESLint проверяет код, Prettier отвечает за форматирование.
|
|
12
|
+
- Bun 1.3.0 or newer
|
|
13
|
+
- Bun as both the runtime and package manager
|
|
14
|
+
- ESLint for code quality and Prettier for formatting
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
Node.js is not required and is not supported as a runtime.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
18
19
|
|
|
19
20
|
```bash
|
|
20
|
-
bun add
|
|
21
|
+
bun add @bruch/max-client
|
|
21
22
|
```
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
Before the package is published, you can install a local checkout:
|
|
24
25
|
|
|
25
26
|
```bash
|
|
26
27
|
bun add ../tsmax
|
|
27
28
|
```
|
|
28
29
|
|
|
29
|
-
## SMS
|
|
30
|
+
## SMS authentication
|
|
30
31
|
|
|
31
32
|
```ts
|
|
32
|
-
import { Client } from "
|
|
33
|
+
import { Client } from "@bruch/max-client";
|
|
33
34
|
|
|
34
35
|
const client = new Client({
|
|
35
36
|
phone: "+79990000000",
|
|
36
|
-
smsCodeProvider: (phone) => prompt(
|
|
37
|
-
passwordProvider: (hint) => prompt(
|
|
37
|
+
smsCodeProvider: (phone) => prompt(`SMS code for ${phone}:`) ?? "",
|
|
38
|
+
passwordProvider: (hint) => prompt(`2FA password${hint ? ` (${hint})` : ""}:`) ?? "",
|
|
38
39
|
});
|
|
39
40
|
|
|
40
41
|
client.onStart(async (app) => {
|
|
41
|
-
console.log(
|
|
42
|
-
await app.sendMessage({ chatId: 123456789n, text: "
|
|
42
|
+
console.log(`Authenticated as ${app.me?.contact.id}`);
|
|
43
|
+
await app.sendMessage({ chatId: 123456789n, text: "Hello from **MAX Client**" });
|
|
43
44
|
});
|
|
44
45
|
|
|
45
46
|
await client.start();
|
|
46
47
|
```
|
|
47
48
|
|
|
48
|
-
`start()`
|
|
49
|
-
|
|
49
|
+
`start()` keeps the client connected until the connection closes. Call `await client.stop()` for a
|
|
50
|
+
graceful shutdown.
|
|
50
51
|
|
|
51
|
-
## QR
|
|
52
|
+
## QR authentication
|
|
52
53
|
|
|
53
54
|
```ts
|
|
54
|
-
import { WebClient } from "
|
|
55
|
+
import { WebClient } from "@bruch/max-client";
|
|
55
56
|
|
|
56
57
|
const client = new WebClient({
|
|
57
|
-
qrHandler: (link) => console.log("
|
|
58
|
+
qrHandler: (link) => console.log("Open this QR link:", link),
|
|
58
59
|
});
|
|
59
60
|
|
|
60
61
|
await client.start();
|
|
61
62
|
```
|
|
62
63
|
|
|
63
|
-
|
|
64
|
+
The default QR handler renders a QR code directly in the terminal.
|
|
64
65
|
|
|
65
|
-
##
|
|
66
|
+
## Events
|
|
66
67
|
|
|
67
68
|
```ts
|
|
68
69
|
client.onMessage(
|
|
@@ -72,22 +73,22 @@ client.onMessage(
|
|
|
72
73
|
(message) => message.chatId !== null,
|
|
73
74
|
);
|
|
74
75
|
|
|
75
|
-
client.onMessageEdit((message) => console.log("
|
|
76
|
+
client.onMessageEdit((message) => console.log("Edited:", message.text));
|
|
76
77
|
client.onTyping((event) => console.log(event.userId, event.typing));
|
|
77
78
|
client.onDisconnect((error, reconnect) => console.error(error.message, { reconnect }));
|
|
78
79
|
```
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
User, chat, and message identifiers are represented as `bigint`. Use the `n` suffix for literals and
|
|
82
|
+
convert identifiers to strings before JSON serialization.
|
|
82
83
|
|
|
83
|
-
##
|
|
84
|
+
## Attachments
|
|
84
85
|
|
|
85
86
|
```ts
|
|
86
|
-
import { File, Photo, Video } from "
|
|
87
|
+
import { File, Photo, Video } from "@bruch/max-client/files";
|
|
87
88
|
|
|
88
89
|
await client.sendMessage({
|
|
89
90
|
chatId: 123456789n,
|
|
90
|
-
text: "
|
|
91
|
+
text: "Files",
|
|
91
92
|
attachments: [
|
|
92
93
|
new Photo({ path: "./photo.jpg" }),
|
|
93
94
|
new Video({ path: "./clip.mp4" }),
|
|
@@ -96,13 +97,14 @@ await client.sendMessage({
|
|
|
96
97
|
});
|
|
97
98
|
```
|
|
98
99
|
|
|
99
|
-
|
|
100
|
+
For videos and files, the client waits for the server-side processing completion event before
|
|
101
|
+
continuing.
|
|
100
102
|
|
|
101
|
-
##
|
|
103
|
+
## Sessions
|
|
102
104
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
Sessions use the SQLite file `session.db` by default. Legacy minimal schemas are migrated
|
|
106
|
+
automatically, and `sync_state` values, tokens, and 64-bit identifiers are stored without precision
|
|
107
|
+
loss.
|
|
106
108
|
|
|
107
109
|
```ts
|
|
108
110
|
const client = new Client({
|
|
@@ -112,13 +114,13 @@ const client = new Client({
|
|
|
112
114
|
});
|
|
113
115
|
```
|
|
114
116
|
|
|
115
|
-
|
|
117
|
+
Never commit session databases. They contain authentication tokens.
|
|
116
118
|
|
|
117
|
-
##
|
|
119
|
+
## Proxies and transports
|
|
118
120
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
The mobile `Client` uses TCP/TLS and supports HTTP CONNECT, HTTPS CONNECT, SOCKS4/4a, and SOCKS5.
|
|
122
|
+
`WebClient` uses Bun's built-in WebSocket implementation; its `proxy` option accepts an HTTP(S)
|
|
123
|
+
proxy in Bun's format.
|
|
122
124
|
|
|
123
125
|
```ts
|
|
124
126
|
const client = new Client({
|
|
@@ -127,42 +129,41 @@ const client = new Client({
|
|
|
127
129
|
});
|
|
128
130
|
```
|
|
129
131
|
|
|
130
|
-
##
|
|
132
|
+
## Development
|
|
131
133
|
|
|
132
134
|
```bash
|
|
133
135
|
bun install
|
|
134
136
|
bun run check
|
|
135
137
|
```
|
|
136
138
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
+
The main commands are `lint`, `format:check`, `typecheck`, `test`, `build`, and `pack:check`. Line,
|
|
140
|
+
function, and statement coverage must remain at or above 90% for modules loaded by the test suite.
|
|
139
141
|
|
|
140
|
-
##
|
|
142
|
+
## Real account smoke test
|
|
141
143
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
144
|
+
`scripts/real-test.ts` verifies a real TCP connection and SMS/2FA authentication. After login, it
|
|
145
|
+
prints the current user, lists active `CHANNEL` subscriptions, and stays connected. Every new post
|
|
146
|
+
is printed with its post ID, channel ID and title, text, and attachment types:
|
|
145
147
|
|
|
146
148
|
```bash
|
|
147
149
|
MAX_PHONE=+79990000000 bun run test:real
|
|
148
150
|
```
|
|
149
151
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
`.data/real-test.db`;
|
|
152
|
+
The test does not send messages or modify the account. Stop it with `Ctrl+C`. Optional environment
|
|
153
|
+
variables are `MAX_PROXY`, `MAX_WORK_DIR`, and `MAX_SESSION_NAME`. The default session is stored in
|
|
154
|
+
`.data/real-test.db`; never publish this file or share it with anyone.
|
|
153
155
|
|
|
154
|
-
##
|
|
156
|
+
## Bun-only runtime
|
|
155
157
|
|
|
156
|
-
|
|
157
|
-
`Bun.
|
|
158
|
-
Cloudflare Workers
|
|
159
|
-
APM
|
|
158
|
+
Using Bun exclusively provides a single runtime and direct access to `bun:sqlite`, `Bun.connect`,
|
|
159
|
+
`Bun.zstdDecompress`, `Bun.file`, and the built-in WebSocket implementation. The tradeoff is that the
|
|
160
|
+
package cannot run in Node.js, Deno, Cloudflare Workers, or most serverless platforms without Bun.
|
|
161
|
+
Node-specific test tooling and APM integrations are not guaranteed to work. The compiled `dist`
|
|
162
|
+
output still targets Bun.
|
|
160
163
|
|
|
161
|
-
##
|
|
164
|
+
## API conventions
|
|
162
165
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
явные providers для интерактивной аутентификации.
|
|
166
|
+
The public API follows TypeScript conventions: `camelCase`, `bigint` identifiers, named event
|
|
167
|
+
methods, and explicit providers for interactive authentication.
|
|
166
168
|
|
|
167
|
-
|
|
168
|
-
атрибуцию исходному PyMax.
|
|
169
|
+
Licensed under the MIT License. This project is unofficial and is not affiliated with MAX.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bruch/max-client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Unofficial Bun/TypeScript client for the Max messenger internal API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,8 +49,7 @@
|
|
|
49
49
|
"dist",
|
|
50
50
|
"src",
|
|
51
51
|
"README.md",
|
|
52
|
-
"LICENSE"
|
|
53
|
-
"UPSTREAM.md"
|
|
52
|
+
"LICENSE"
|
|
54
53
|
],
|
|
55
54
|
"scripts": {
|
|
56
55
|
"build": "bun run clean && bun build src/index.ts src/auth/index.ts src/files/index.ts src/protocol/index.ts src/session/index.ts src/telemetry/index.ts src/types/index.ts --outdir dist --target bun --format esm --packages external --sourcemap=external && tsc -p tsconfig.build.json",
|
package/UPSTREAM.md
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
# Upstream
|
|
2
|
-
|
|
3
|
-
`tsmax` is a TypeScript/Bun port of [MaxApiTeam/PyMax](https://github.com/MaxApiTeam/PyMax).
|
|
4
|
-
|
|
5
|
-
- Compatibility baseline: PyMax 2.3.1
|
|
6
|
-
- Git commit: `8c40b71`
|
|
7
|
-
- Upstream license: MIT
|
|
8
|
-
|
|
9
|
-
The local `PyMax/` checkout is used only as a development reference and is not included in the
|
|
10
|
-
published package.
|