@mtcute/core 0.25.4 → 0.25.5

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.
@@ -24,39 +24,122 @@ import { InputStringSessionData } from './utils/string-session.js';
24
24
  */
25
25
  export type ConnectionState = 'offline' | 'connecting' | 'updating' | 'connected';
26
26
  export interface ITelegramClient {
27
+ /** Logger for the client */
27
28
  readonly log: Logger;
29
+ /** Storage manager */
28
30
  readonly storage: PublicPart<TelegramStorageManager>;
31
+ /** App config manager */
29
32
  readonly appConfig: PublicPart<AppConfigManager>;
33
+ /** Timers manager */
30
34
  readonly timers: Pick<TimersManager, 'create' | 'cancel' | 'exists'>;
35
+ /** Signal that will be aborted when the client is destroyed */
31
36
  readonly stopSignal: AbortSignal;
37
+ /** Platform used by the client */
32
38
  readonly platform: ICorePlatform;
39
+ /**
40
+ * **ADVANCED**
41
+ *
42
+ * Do all the preparations, but don't connect just yet.
43
+ * Useful when you want to do some preparations before
44
+ * connecting, like setting up session.
45
+ *
46
+ * Call {@link connect} to actually connect.
47
+ */
33
48
  prepare(): Promise<void>;
49
+ /**
50
+ * Initialize the connection to the primary DC.
51
+ *
52
+ * You shouldn't usually call this method directly as it is called
53
+ * implicitly the first time you call {@link call}.
54
+ */
34
55
  connect(): Promise<void>;
56
+ /**
57
+ * Terminate any connections to the Telegram servers, but keep the client usable
58
+ */
35
59
  disconnect(): Promise<void>;
60
+ /**
61
+ * Destroy the client and all its resources.
62
+ *
63
+ * This will terminate any connections to the Telegram servers,
64
+ * free all the resources, and make the client no longer usable
65
+ */
36
66
  destroy(): Promise<void>;
67
+ /** Notify the client that the user has logged in */
37
68
  notifyLoggedIn(auth: tl.auth.TypeAuthorization | tl.RawUser): Promise<tl.RawUser>;
69
+ /** Notify the client that the user has logged out */
38
70
  notifyLoggedOut(): Promise<void>;
71
+ /** Notify the client that a channel has been opened */
39
72
  notifyChannelOpened(channelId: number, pts?: number): Promise<boolean>;
73
+ /** Notify the client that a channel has been closed */
40
74
  notifyChannelClosed(channelId: number): Promise<boolean>;
75
+ /** Start the updates loop */
41
76
  startUpdatesLoop(): Promise<void>;
77
+ /** Stop the updates loop */
42
78
  stopUpdatesLoop(): Promise<void>;
79
+ /** Call an RPC method */
43
80
  call<T extends tl.RpcMethod>(message: MustEqual<T, tl.RpcMethod>, params?: RpcCallOptions): Promise<tl.RpcCallReturn[T['_']]>;
81
+ /**
82
+ * Import the session from the given session string.
83
+ *
84
+ * Note that the session will only be imported in case
85
+ * the storage is missing authorization (i.e. does not contain
86
+ * auth key for the primary DC), otherwise it will be ignored (unless `force`).
87
+ *
88
+ * @param session Session string to import
89
+ * @param force Whether to overwrite existing session
90
+ */
44
91
  importSession(session: string | InputStringSessionData, force?: boolean): Promise<void>;
92
+ /**
93
+ * Export current session to a single *LONG* string, containing
94
+ * all the needed information.
95
+ *
96
+ * > **Warning!** Anyone with this string will be able
97
+ * > to authorize as you and do anything. Treat this
98
+ * > as your password, and never give it away!
99
+ * >
100
+ * > In case you have accidentally leaked this string,
101
+ * > make sure to revoke this session in account settings:
102
+ * > "Privacy & Security" > "Active sessions" >
103
+ * > find the one containing `mtcute` > Revoke,
104
+ * > or, in case this is a bot, revoke bot token
105
+ * > with [@BotFather](//t.me/botfather)
106
+ */
45
107
  exportSession(): Promise<string>;
108
+ /**
109
+ * Handle an update sent by the server in response to an RPC call
110
+ *
111
+ * @param updates Updates to handle
112
+ * @param noDispatch Whether the updates inside should not be dispatched as events
113
+ */
46
114
  handleClientUpdate(updates: tl.TypeUpdates, noDispatch?: boolean): void;
115
+ /** Emitted when a low-level `Updates` updates is received */
47
116
  onServerUpdate: Emitter<tl.TypeUpdates>;
117
+ /** Emitted when an update is received from the server. Requires updates loop to be running */
48
118
  onRawUpdate: Emitter<RawUpdateInfo>;
119
+ /** Emitted when the connection state changes */
49
120
  onConnectionState: Emitter<ConnectionState>;
121
+ /** Emitted when an error occurs */
50
122
  onError: Emitter<Error>;
123
+ /** Get the API credentials for use in authorization methods */
51
124
  getApiCredentials(): Promise<{
52
125
  id: number;
53
126
  hash: string;
54
127
  }>;
128
+ /** Get the number of connections of the given kind */
55
129
  getPoolSize(kind: ConnectionKind, dcId?: number): Promise<number>;
130
+ /** Get the primary DC ID */
56
131
  getPrimaryDcId(): Promise<number>;
132
+ /** Change the primary DC */
57
133
  changePrimaryDc(newDc: number): Promise<void>;
134
+ /** Compute SRP parameters for the given password */
58
135
  computeSrpParams(request: tl.account.RawPassword, password: string): Promise<tl.RawInputCheckPasswordSRP>;
136
+ /** Compute new password hash for the given algorithm and password */
59
137
  computeNewPasswordHash(algo: tl.TypePasswordKdfAlgo, password: string): Promise<Uint8Array>;
138
+ /** Generate a new time-based MTProto message ID */
60
139
  getMtprotoMessageId(): Promise<Long>;
140
+ /**
141
+ * **ADVANCED**
142
+ * Recreate the given DC, forcefully using the IP taken from server config.
143
+ */
61
144
  recreateDc(dcId: number): Promise<void>;
62
145
  }
@@ -24,39 +24,122 @@ import { InputStringSessionData } from './utils/string-session.js';
24
24
  */
25
25
  export type ConnectionState = 'offline' | 'connecting' | 'updating' | 'connected';
26
26
  export interface ITelegramClient {
27
+ /** Logger for the client */
27
28
  readonly log: Logger;
29
+ /** Storage manager */
28
30
  readonly storage: PublicPart<TelegramStorageManager>;
31
+ /** App config manager */
29
32
  readonly appConfig: PublicPart<AppConfigManager>;
33
+ /** Timers manager */
30
34
  readonly timers: Pick<TimersManager, 'create' | 'cancel' | 'exists'>;
35
+ /** Signal that will be aborted when the client is destroyed */
31
36
  readonly stopSignal: AbortSignal;
37
+ /** Platform used by the client */
32
38
  readonly platform: ICorePlatform;
39
+ /**
40
+ * **ADVANCED**
41
+ *
42
+ * Do all the preparations, but don't connect just yet.
43
+ * Useful when you want to do some preparations before
44
+ * connecting, like setting up session.
45
+ *
46
+ * Call {@link connect} to actually connect.
47
+ */
33
48
  prepare(): Promise<void>;
49
+ /**
50
+ * Initialize the connection to the primary DC.
51
+ *
52
+ * You shouldn't usually call this method directly as it is called
53
+ * implicitly the first time you call {@link call}.
54
+ */
34
55
  connect(): Promise<void>;
56
+ /**
57
+ * Terminate any connections to the Telegram servers, but keep the client usable
58
+ */
35
59
  disconnect(): Promise<void>;
60
+ /**
61
+ * Destroy the client and all its resources.
62
+ *
63
+ * This will terminate any connections to the Telegram servers,
64
+ * free all the resources, and make the client no longer usable
65
+ */
36
66
  destroy(): Promise<void>;
67
+ /** Notify the client that the user has logged in */
37
68
  notifyLoggedIn(auth: tl.auth.TypeAuthorization | tl.RawUser): Promise<tl.RawUser>;
69
+ /** Notify the client that the user has logged out */
38
70
  notifyLoggedOut(): Promise<void>;
71
+ /** Notify the client that a channel has been opened */
39
72
  notifyChannelOpened(channelId: number, pts?: number): Promise<boolean>;
73
+ /** Notify the client that a channel has been closed */
40
74
  notifyChannelClosed(channelId: number): Promise<boolean>;
75
+ /** Start the updates loop */
41
76
  startUpdatesLoop(): Promise<void>;
77
+ /** Stop the updates loop */
42
78
  stopUpdatesLoop(): Promise<void>;
79
+ /** Call an RPC method */
43
80
  call<T extends tl.RpcMethod>(message: MustEqual<T, tl.RpcMethod>, params?: RpcCallOptions): Promise<tl.RpcCallReturn[T['_']]>;
81
+ /**
82
+ * Import the session from the given session string.
83
+ *
84
+ * Note that the session will only be imported in case
85
+ * the storage is missing authorization (i.e. does not contain
86
+ * auth key for the primary DC), otherwise it will be ignored (unless `force`).
87
+ *
88
+ * @param session Session string to import
89
+ * @param force Whether to overwrite existing session
90
+ */
44
91
  importSession(session: string | InputStringSessionData, force?: boolean): Promise<void>;
92
+ /**
93
+ * Export current session to a single *LONG* string, containing
94
+ * all the needed information.
95
+ *
96
+ * > **Warning!** Anyone with this string will be able
97
+ * > to authorize as you and do anything. Treat this
98
+ * > as your password, and never give it away!
99
+ * >
100
+ * > In case you have accidentally leaked this string,
101
+ * > make sure to revoke this session in account settings:
102
+ * > "Privacy & Security" > "Active sessions" >
103
+ * > find the one containing `mtcute` > Revoke,
104
+ * > or, in case this is a bot, revoke bot token
105
+ * > with [@BotFather](//t.me/botfather)
106
+ */
45
107
  exportSession(): Promise<string>;
108
+ /**
109
+ * Handle an update sent by the server in response to an RPC call
110
+ *
111
+ * @param updates Updates to handle
112
+ * @param noDispatch Whether the updates inside should not be dispatched as events
113
+ */
46
114
  handleClientUpdate(updates: tl.TypeUpdates, noDispatch?: boolean): void;
115
+ /** Emitted when a low-level `Updates` updates is received */
47
116
  onServerUpdate: Emitter<tl.TypeUpdates>;
117
+ /** Emitted when an update is received from the server. Requires updates loop to be running */
48
118
  onRawUpdate: Emitter<RawUpdateInfo>;
119
+ /** Emitted when the connection state changes */
49
120
  onConnectionState: Emitter<ConnectionState>;
121
+ /** Emitted when an error occurs */
50
122
  onError: Emitter<Error>;
123
+ /** Get the API credentials for use in authorization methods */
51
124
  getApiCredentials(): Promise<{
52
125
  id: number;
53
126
  hash: string;
54
127
  }>;
128
+ /** Get the number of connections of the given kind */
55
129
  getPoolSize(kind: ConnectionKind, dcId?: number): Promise<number>;
130
+ /** Get the primary DC ID */
56
131
  getPrimaryDcId(): Promise<number>;
132
+ /** Change the primary DC */
57
133
  changePrimaryDc(newDc: number): Promise<void>;
134
+ /** Compute SRP parameters for the given password */
58
135
  computeSrpParams(request: tl.account.RawPassword, password: string): Promise<tl.RawInputCheckPasswordSRP>;
136
+ /** Compute new password hash for the given algorithm and password */
59
137
  computeNewPasswordHash(algo: tl.TypePasswordKdfAlgo, password: string): Promise<Uint8Array>;
138
+ /** Generate a new time-based MTProto message ID */
60
139
  getMtprotoMessageId(): Promise<Long>;
140
+ /**
141
+ * **ADVANCED**
142
+ * Recreate the given DC, forcefully using the IP taken from server config.
143
+ */
61
144
  recreateDc(dcId: number): Promise<void>;
62
145
  }
@@ -225,7 +225,7 @@ class NetworkManager {
225
225
  _: "initConnection",
226
226
  deviceModel,
227
227
  systemVersion: "1.0",
228
- appVersion: "0.25.4",
228
+ appVersion: "0.25.5",
229
229
  systemLangCode: "en",
230
230
  langPack: "",
231
231
  // "langPacks are for official apps only"
@@ -218,7 +218,7 @@ class NetworkManager {
218
218
  _: "initConnection",
219
219
  deviceModel,
220
220
  systemVersion: "1.0",
221
- appVersion: "0.25.4",
221
+ appVersion: "0.25.5",
222
222
  systemLangCode: "en",
223
223
  langPack: "",
224
224
  // "langPacks are for official apps only"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mtcute/core",
3
3
  "type": "module",
4
- "version": "0.25.4",
4
+ "version": "0.25.5",
5
5
  "description": "Type-safe library for MTProto (Telegram API)",
6
6
  "license": "MIT",
7
7
  "scripts": {},
@@ -10,7 +10,7 @@
10
10
  "@fuman/net": "0.0.15",
11
11
  "@fuman/utils": "0.0.15",
12
12
  "@mtcute/file-id": "^0.24.3",
13
- "@mtcute/tl": "^208.0.0",
13
+ "@mtcute/tl": "^209.0.0",
14
14
  "@mtcute/tl-runtime": "^0.24.3",
15
15
  "@types/events": "3.0.0",
16
16
  "long": "5.2.3"