@mtkruto/node 0.0.975 → 0.0.977

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.
@@ -32,7 +32,7 @@ export interface ClientParams {
32
32
  */
33
33
  parseMode?: ParseMode;
34
34
  /**
35
- * The transport provider to use. Defaults to `defaultTransportProvider`.
35
+ * The transport provider to use. Defaults to `webSocketTransportProvider`.
36
36
  */
37
37
  transportProvider?: TransportProvider;
38
38
  /**
@@ -59,7 +59,14 @@ export interface ClientParams {
59
59
  * The system_version parameter to be passed to initConnection when calling `authorize`.
60
60
  */
61
61
  systemVersion?: string;
62
+ /**
63
+ * MTProto public keys to use in the `[keyId, [key, exponent]][]` format. Don't set this unless you know what you are doing.
64
+ */
62
65
  publicKeys?: PublicKeys;
66
+ /**
67
+ * Whether to automatically call `start` with no parameters in the first `invoke` call.
68
+ */
69
+ autoStart?: boolean;
63
70
  }
64
71
  export interface ForwardMessagesParams {
65
72
  messageThreadId?: number;
@@ -88,6 +95,7 @@ export declare class Client extends ClientAbstract {
88
95
  readonly systemLangCode: string;
89
96
  readonly systemVersion: string;
90
97
  private readonly publicKeys?;
98
+ private readonly autoStart;
91
99
  /**
92
100
  * Constructs the client.
93
101
  *
@@ -132,8 +140,13 @@ export declare class Client extends ClientAbstract {
132
140
  * [2]: https://core.telegram.org/method/updates.getState
133
141
  */
134
142
  authorize(params?: string | types.AuthExportedAuthorization | AuthorizeUserParams): Promise<void>;
143
+ /**
144
+ * Same as calling `.connect()` followed by `.authorize(params)`.
145
+ */
146
+ start(params?: string | types.AuthExportedAuthorization | AuthorizeUserParams): Promise<void>;
135
147
  private receiveLoop;
136
148
  private pingLoop;
149
+ private autoStarted;
137
150
  private lastMsgId;
138
151
  /**
139
152
  * Invokes a function waiting and returning its reply if the second parameter is not `true`. Requires the client
@@ -160,12 +160,24 @@ export class Client extends ClientAbstract {
160
160
  writable: true,
161
161
  value: void 0
162
162
  });
163
+ Object.defineProperty(this, "autoStart", {
164
+ enumerable: true,
165
+ configurable: true,
166
+ writable: true,
167
+ value: void 0
168
+ });
163
169
  Object.defineProperty(this, "storageInited", {
164
170
  enumerable: true,
165
171
  configurable: true,
166
172
  writable: true,
167
173
  value: false
168
174
  });
175
+ Object.defineProperty(this, "autoStarted", {
176
+ enumerable: true,
177
+ configurable: true,
178
+ writable: true,
179
+ value: false
180
+ });
169
181
  Object.defineProperty(this, "lastMsgId", {
170
182
  enumerable: true,
171
183
  configurable: true,
@@ -198,6 +210,7 @@ export class Client extends ClientAbstract {
198
210
  this.systemLangCode = params?.systemLangCode ?? SYSTEM_LANG_CODE;
199
211
  this.systemVersion = params?.systemVersion ?? SYSTEM_VERSION;
200
212
  this.publicKeys = params?.publicKeys;
213
+ this.autoStart = params?.autoStart ?? true;
201
214
  }
202
215
  /**
203
216
  * Sets the DC and resets the auth key stored in the session provider
@@ -473,6 +486,13 @@ export class Client extends ClientAbstract {
473
486
  }
474
487
  }
475
488
  }
489
+ /**
490
+ * Same as calling `.connect()` followed by `.authorize(params)`.
491
+ */
492
+ async start(params) {
493
+ await this.connect();
494
+ await this.authorize(params);
495
+ }
476
496
  async receiveLoop() {
477
497
  if (!this.auth) {
478
498
  throw new Error("Not connected");
@@ -578,7 +598,15 @@ export class Client extends ClientAbstract {
578
598
  }
579
599
  async invoke(function_, noWait) {
580
600
  if (!this.auth) {
581
- throw new Error("Not connected");
601
+ if (this.autoStart && !this.autoStarted) {
602
+ await this.start();
603
+ }
604
+ else {
605
+ throw new Error("Not connected");
606
+ }
607
+ }
608
+ if (!this.auth) {
609
+ UNREACHABLE();
582
610
  }
583
611
  let seqNo = this.state.seqNo * 2;
584
612
  if (!(function_ instanceof functions.Ping) && !(function_ instanceof types.MsgsAck)) {
@@ -5,7 +5,7 @@ export declare const PUBLIC_KEYS: PublicKeys;
5
5
  export declare const VECTOR_CONSTRUCTOR = 481674261;
6
6
  export declare const INITIAL_DC: DC;
7
7
  export declare const LAYER = 160;
8
- export declare const APP_VERSION = "MTKruto 0.0.975";
8
+ export declare const APP_VERSION = "MTKruto 0.0.977";
9
9
  export declare const DEVICE_MODEL: string;
10
10
  export declare const LANG_CODE: string;
11
11
  export declare const LANG_PACK = "";
package/esm/constants.js CHANGED
@@ -54,7 +54,7 @@ export const PUBLIC_KEYS = Object.freeze([
54
54
  export const VECTOR_CONSTRUCTOR = 0x1CB5C415;
55
55
  export const INITIAL_DC = "2-test";
56
56
  export const LAYER = 160;
57
- export const APP_VERSION = "MTKruto 0.0.975";
57
+ export const APP_VERSION = "MTKruto 0.0.977";
58
58
  // @ts-ignore: lib
59
59
  export const DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
60
60
  export const LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "module": "./esm/mod.js",
3
3
  "main": "./script/mod.js",
4
4
  "name": "@mtkruto/node",
5
- "version": "0.0.975",
5
+ "version": "0.0.977",
6
6
  "description": "MTKruto for Node.js",
7
7
  "author": "Roj <rojvv@icloud.com>",
8
8
  "license": "LGPL-3.0-or-later",
@@ -32,7 +32,7 @@ export interface ClientParams {
32
32
  */
33
33
  parseMode?: ParseMode;
34
34
  /**
35
- * The transport provider to use. Defaults to `defaultTransportProvider`.
35
+ * The transport provider to use. Defaults to `webSocketTransportProvider`.
36
36
  */
37
37
  transportProvider?: TransportProvider;
38
38
  /**
@@ -59,7 +59,14 @@ export interface ClientParams {
59
59
  * The system_version parameter to be passed to initConnection when calling `authorize`.
60
60
  */
61
61
  systemVersion?: string;
62
+ /**
63
+ * MTProto public keys to use in the `[keyId, [key, exponent]][]` format. Don't set this unless you know what you are doing.
64
+ */
62
65
  publicKeys?: PublicKeys;
66
+ /**
67
+ * Whether to automatically call `start` with no parameters in the first `invoke` call.
68
+ */
69
+ autoStart?: boolean;
63
70
  }
64
71
  export interface ForwardMessagesParams {
65
72
  messageThreadId?: number;
@@ -88,6 +95,7 @@ export declare class Client extends ClientAbstract {
88
95
  readonly systemLangCode: string;
89
96
  readonly systemVersion: string;
90
97
  private readonly publicKeys?;
98
+ private readonly autoStart;
91
99
  /**
92
100
  * Constructs the client.
93
101
  *
@@ -132,8 +140,13 @@ export declare class Client extends ClientAbstract {
132
140
  * [2]: https://core.telegram.org/method/updates.getState
133
141
  */
134
142
  authorize(params?: string | types.AuthExportedAuthorization | AuthorizeUserParams): Promise<void>;
143
+ /**
144
+ * Same as calling `.connect()` followed by `.authorize(params)`.
145
+ */
146
+ start(params?: string | types.AuthExportedAuthorization | AuthorizeUserParams): Promise<void>;
135
147
  private receiveLoop;
136
148
  private pingLoop;
149
+ private autoStarted;
137
150
  private lastMsgId;
138
151
  /**
139
152
  * Invokes a function waiting and returning its reply if the second parameter is not `true`. Requires the client
@@ -186,12 +186,24 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
186
186
  writable: true,
187
187
  value: void 0
188
188
  });
189
+ Object.defineProperty(this, "autoStart", {
190
+ enumerable: true,
191
+ configurable: true,
192
+ writable: true,
193
+ value: void 0
194
+ });
189
195
  Object.defineProperty(this, "storageInited", {
190
196
  enumerable: true,
191
197
  configurable: true,
192
198
  writable: true,
193
199
  value: false
194
200
  });
201
+ Object.defineProperty(this, "autoStarted", {
202
+ enumerable: true,
203
+ configurable: true,
204
+ writable: true,
205
+ value: false
206
+ });
195
207
  Object.defineProperty(this, "lastMsgId", {
196
208
  enumerable: true,
197
209
  configurable: true,
@@ -224,6 +236,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
224
236
  this.systemLangCode = params?.systemLangCode ?? constants_js_1.SYSTEM_LANG_CODE;
225
237
  this.systemVersion = params?.systemVersion ?? constants_js_1.SYSTEM_VERSION;
226
238
  this.publicKeys = params?.publicKeys;
239
+ this.autoStart = params?.autoStart ?? true;
227
240
  }
228
241
  /**
229
242
  * Sets the DC and resets the auth key stored in the session provider
@@ -499,6 +512,13 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
499
512
  }
500
513
  }
501
514
  }
515
+ /**
516
+ * Same as calling `.connect()` followed by `.authorize(params)`.
517
+ */
518
+ async start(params) {
519
+ await this.connect();
520
+ await this.authorize(params);
521
+ }
502
522
  async receiveLoop() {
503
523
  if (!this.auth) {
504
524
  throw new Error("Not connected");
@@ -604,7 +624,15 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
604
624
  }
605
625
  async invoke(function_, noWait) {
606
626
  if (!this.auth) {
607
- throw new Error("Not connected");
627
+ if (this.autoStart && !this.autoStarted) {
628
+ await this.start();
629
+ }
630
+ else {
631
+ throw new Error("Not connected");
632
+ }
633
+ }
634
+ if (!this.auth) {
635
+ (0, _0_control_js_1.UNREACHABLE)();
608
636
  }
609
637
  let seqNo = this.state.seqNo * 2;
610
638
  if (!(function_ instanceof functions.Ping) && !(function_ instanceof types.MsgsAck)) {
@@ -5,7 +5,7 @@ export declare const PUBLIC_KEYS: PublicKeys;
5
5
  export declare const VECTOR_CONSTRUCTOR = 481674261;
6
6
  export declare const INITIAL_DC: DC;
7
7
  export declare const LAYER = 160;
8
- export declare const APP_VERSION = "MTKruto 0.0.975";
8
+ export declare const APP_VERSION = "MTKruto 0.0.977";
9
9
  export declare const DEVICE_MODEL: string;
10
10
  export declare const LANG_CODE: string;
11
11
  export declare const LANG_PACK = "";
@@ -80,7 +80,7 @@ exports.PUBLIC_KEYS = Object.freeze([
80
80
  exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
81
81
  exports.INITIAL_DC = "2-test";
82
82
  exports.LAYER = 160;
83
- exports.APP_VERSION = "MTKruto 0.0.975";
83
+ exports.APP_VERSION = "MTKruto 0.0.977";
84
84
  // @ts-ignore: lib
85
85
  exports.DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
86
86
  exports.LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];