@armatofik/tgsnake-core 1.13.15

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.

Potentially problematic release.


This version of @armatofik/tgsnake-core might be problematic. Click here for more details.

Files changed (171) hide show
  1. package/COPYING +674 -0
  2. package/COPYING.lesser +165 -0
  3. package/README.md +88 -0
  4. package/lib/package.json +46 -0
  5. package/lib/src/Logger.d.ts +3 -0
  6. package/lib/src/Logger.js +9 -0
  7. package/lib/src/Queue.d.ts +19 -0
  8. package/lib/src/Queue.js +52 -0
  9. package/lib/src/Timeout.d.ts +9 -0
  10. package/lib/src/Timeout.js +44 -0
  11. package/lib/src/Version.node.d.ts +4 -0
  12. package/lib/src/Version.node.js +26 -0
  13. package/lib/src/client/Auth.d.ts +40 -0
  14. package/lib/src/client/Auth.js +317 -0
  15. package/lib/src/client/Client.d.ts +83 -0
  16. package/lib/src/client/Client.js +461 -0
  17. package/lib/src/client/Session.d.ts +9 -0
  18. package/lib/src/client/Session.js +132 -0
  19. package/lib/src/client/index.d.ts +3 -0
  20. package/lib/src/client/index.js +39 -0
  21. package/lib/src/connection/TCP/TCPAbridged.d.ts +9 -0
  22. package/lib/src/connection/TCP/TCPAbridged.js +47 -0
  23. package/lib/src/connection/TCP/TCPAbridgedO.d.ts +12 -0
  24. package/lib/src/connection/TCP/TCPAbridgedO.js +140 -0
  25. package/lib/src/connection/TCP/TCPFull.d.ts +10 -0
  26. package/lib/src/connection/TCP/TCPFull.js +43 -0
  27. package/lib/src/connection/TCP/TCPIntermediate.d.ts +9 -0
  28. package/lib/src/connection/TCP/TCPIntermediate.js +31 -0
  29. package/lib/src/connection/TCP/TCPIntermediateO.d.ts +12 -0
  30. package/lib/src/connection/TCP/TCPIntermediateO.js +123 -0
  31. package/lib/src/connection/TCP/TCPPaddedIntermediate.d.ts +9 -0
  32. package/lib/src/connection/TCP/TCPPaddedIntermediate.js +38 -0
  33. package/lib/src/connection/TCP/index.d.ts +7 -0
  34. package/lib/src/connection/TCP/index.js +17 -0
  35. package/lib/src/connection/TCP/tcp.d.ts +17 -0
  36. package/lib/src/connection/TCP/tcp.js +98 -0
  37. package/lib/src/connection/WebSocket.d.ts +21 -0
  38. package/lib/src/connection/WebSocket.js +279 -0
  39. package/lib/src/connection/connection.d.ts +53 -0
  40. package/lib/src/connection/connection.js +189 -0
  41. package/lib/src/connection/index.d.ts +4 -0
  42. package/lib/src/connection/index.js +41 -0
  43. package/lib/src/crypto/Aes.d.ts +10 -0
  44. package/lib/src/crypto/Aes.js +135 -0
  45. package/lib/src/crypto/Mtproto.d.ts +5 -0
  46. package/lib/src/crypto/Mtproto.js +123 -0
  47. package/lib/src/crypto/Password.d.ts +5 -0
  48. package/lib/src/crypto/Password.js +92 -0
  49. package/lib/src/crypto/Prime.d.ts +4 -0
  50. package/lib/src/crypto/Prime.js +64 -0
  51. package/lib/src/crypto/RSA.d.ts +7 -0
  52. package/lib/src/crypto/RSA.js +99 -0
  53. package/lib/src/crypto/SecretChat.d.ts +5 -0
  54. package/lib/src/crypto/SecretChat.js +136 -0
  55. package/lib/src/crypto/index.d.ts +6 -0
  56. package/lib/src/crypto/index.js +42 -0
  57. package/lib/src/errors/Base.d.ts +9 -0
  58. package/lib/src/errors/Base.js +50 -0
  59. package/lib/src/errors/Client.d.ts +21 -0
  60. package/lib/src/errors/Client.js +29 -0
  61. package/lib/src/errors/File.d.ts +13 -0
  62. package/lib/src/errors/File.js +30 -0
  63. package/lib/src/errors/RpcError.d.ts +22 -0
  64. package/lib/src/errors/RpcError.js +120 -0
  65. package/lib/src/errors/SecretChat.d.ts +13 -0
  66. package/lib/src/errors/SecretChat.js +30 -0
  67. package/lib/src/errors/WebSocket.d.ts +13 -0
  68. package/lib/src/errors/WebSocket.js +30 -0
  69. package/lib/src/errors/exceptions/All.d.ts +774 -0
  70. package/lib/src/errors/exceptions/All.js +778 -0
  71. package/lib/src/errors/exceptions/BadRequest400.d.ts +2345 -0
  72. package/lib/src/errors/exceptions/BadRequest400.js +2945 -0
  73. package/lib/src/errors/exceptions/Flood420.d.ts +37 -0
  74. package/lib/src/errors/exceptions/Flood420.js +49 -0
  75. package/lib/src/errors/exceptions/Forbidden403.d.ts +205 -0
  76. package/lib/src/errors/exceptions/Forbidden403.js +260 -0
  77. package/lib/src/errors/exceptions/InternalServerError500.d.ts +221 -0
  78. package/lib/src/errors/exceptions/InternalServerError500.js +280 -0
  79. package/lib/src/errors/exceptions/NotAcceptable406.d.ts +117 -0
  80. package/lib/src/errors/exceptions/NotAcceptable406.js +149 -0
  81. package/lib/src/errors/exceptions/NotFound404.d.ts +9 -0
  82. package/lib/src/errors/exceptions/NotFound404.js +14 -0
  83. package/lib/src/errors/exceptions/SeeOther303.d.ts +25 -0
  84. package/lib/src/errors/exceptions/SeeOther303.js +34 -0
  85. package/lib/src/errors/exceptions/ServiceUnavailable503.d.ts +17 -0
  86. package/lib/src/errors/exceptions/ServiceUnavailable503.js +24 -0
  87. package/lib/src/errors/exceptions/Unauthorized401.d.ts +41 -0
  88. package/lib/src/errors/exceptions/Unauthorized401.js +54 -0
  89. package/lib/src/errors/exceptions/index.d.ts +10 -0
  90. package/lib/src/errors/exceptions/index.js +48 -0
  91. package/lib/src/errors/index.d.ts +31 -0
  92. package/lib/src/errors/index.js +111 -0
  93. package/lib/src/file/Download.d.ts +11 -0
  94. package/lib/src/file/Download.js +118 -0
  95. package/lib/src/file/File.d.ts +20 -0
  96. package/lib/src/file/File.js +82 -0
  97. package/lib/src/file/Upload.d.ts +19 -0
  98. package/lib/src/file/Upload.js +250 -0
  99. package/lib/src/file/index.d.ts +3 -0
  100. package/lib/src/file/index.js +11 -0
  101. package/lib/src/helpers.d.ts +34 -0
  102. package/lib/src/helpers.js +358 -0
  103. package/lib/src/index.d.ts +16 -0
  104. package/lib/src/index.js +56 -0
  105. package/lib/src/platform.node.d.ts +36 -0
  106. package/lib/src/platform.node.js +109 -0
  107. package/lib/src/raw/All.d.ts +2400 -0
  108. package/lib/src/raw/All.js +2403 -0
  109. package/lib/src/raw/Raw.d.ts +29195 -0
  110. package/lib/src/raw/Raw.js +97277 -0
  111. package/lib/src/raw/core/BytesIO.d.ts +33 -0
  112. package/lib/src/raw/core/BytesIO.js +145 -0
  113. package/lib/src/raw/core/GzipPacked.d.ts +10 -0
  114. package/lib/src/raw/core/GzipPacked.js +60 -0
  115. package/lib/src/raw/core/Message.d.ts +13 -0
  116. package/lib/src/raw/core/Message.js +81 -0
  117. package/lib/src/raw/core/MsgContainer.d.ts +11 -0
  118. package/lib/src/raw/core/MsgContainer.js +69 -0
  119. package/lib/src/raw/core/TLObject.d.ts +19 -0
  120. package/lib/src/raw/core/TLObject.js +108 -0
  121. package/lib/src/raw/core/UpdateSecretChat.d.ts +40 -0
  122. package/lib/src/raw/core/UpdateSecretChat.js +88 -0
  123. package/lib/src/raw/core/index.d.ts +8 -0
  124. package/lib/src/raw/core/index.js +52 -0
  125. package/lib/src/raw/core/primitive/Bool.d.ts +20 -0
  126. package/lib/src/raw/core/primitive/Bool.js +41 -0
  127. package/lib/src/raw/core/primitive/Bytes.d.ts +7 -0
  128. package/lib/src/raw/core/primitive/Bytes.js +41 -0
  129. package/lib/src/raw/core/primitive/Double.d.ts +7 -0
  130. package/lib/src/raw/core/primitive/Double.js +24 -0
  131. package/lib/src/raw/core/primitive/Float.d.ts +7 -0
  132. package/lib/src/raw/core/primitive/Float.js +24 -0
  133. package/lib/src/raw/core/primitive/Int.d.ts +23 -0
  134. package/lib/src/raw/core/primitive/Int.js +122 -0
  135. package/lib/src/raw/core/primitive/String.d.ts +7 -0
  136. package/lib/src/raw/core/primitive/String.js +15 -0
  137. package/lib/src/raw/core/primitive/Vector.d.ts +9 -0
  138. package/lib/src/raw/core/primitive/Vector.js +50 -0
  139. package/lib/src/raw/core/primitive/index.d.ts +7 -0
  140. package/lib/src/raw/core/primitive/index.js +22 -0
  141. package/lib/src/raw/index.d.ts +3 -0
  142. package/lib/src/raw/index.js +17 -0
  143. package/lib/src/session/Auth.d.ts +15 -0
  144. package/lib/src/session/Auth.js +254 -0
  145. package/lib/src/session/Session.d.ts +58 -0
  146. package/lib/src/session/Session.js +571 -0
  147. package/lib/src/session/index.d.ts +7 -0
  148. package/lib/src/session/index.js +49 -0
  149. package/lib/src/session/internals/DataCenter.d.ts +42 -0
  150. package/lib/src/session/internals/DataCenter.js +80 -0
  151. package/lib/src/session/internals/MsgFactory.d.ts +3 -0
  152. package/lib/src/session/internals/MsgFactory.js +23 -0
  153. package/lib/src/session/internals/MsgId.d.ts +9 -0
  154. package/lib/src/session/internals/MsgId.js +24 -0
  155. package/lib/src/session/internals/SeqNo.d.ts +6 -0
  156. package/lib/src/session/internals/SeqNo.js +18 -0
  157. package/lib/src/session/secretChats/SecretChat.d.ts +29 -0
  158. package/lib/src/session/secretChats/SecretChat.js +527 -0
  159. package/lib/src/session/secretChats/index.d.ts +1 -0
  160. package/lib/src/session/secretChats/index.js +5 -0
  161. package/lib/src/storage/Abstract.d.ts +68 -0
  162. package/lib/src/storage/Abstract.js +6 -0
  163. package/lib/src/storage/SecretChat.d.ts +42 -0
  164. package/lib/src/storage/SecretChat.js +99 -0
  165. package/lib/src/storage/Session.d.ts +63 -0
  166. package/lib/src/storage/Session.js +245 -0
  167. package/lib/src/storage/StringSession.d.ts +4 -0
  168. package/lib/src/storage/StringSession.js +77 -0
  169. package/lib/src/storage/index.d.ts +4 -0
  170. package/lib/src/storage/index.js +12 -0
  171. package/package.json +46 -0
package/COPYING.lesser ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
package/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # tgsnake core
2
+
3
+ <center>
4
+ <b>Layer 222</b>
5
+ </center>
6
+
7
+ ---
8
+
9
+ Pure Telegram MTProto framework for Javascript or Typescript.
10
+
11
+ ⚡ Using less dependencies to make it fast.
12
+ 🔓 Open Source, you can contribute to make this framework better.
13
+ 🗒️ Using Pure Telegram Raw Api, all JSON object is pure from telegram, nothing has changed at all. So that it makes it easier for you to learn the [telegram schema](https://core.telegram.org/schema) docs.
14
+ 🦕 Deno Support.
15
+
16
+ ## Example use
17
+
18
+ ```typescript
19
+ import { Client, Raw, Storages } from '@tgsnake/core';
20
+ process.env.LOGLEVEL = 'debug'; // set log level, see @tgsnake/log for more information.
21
+ const client = new Client(
22
+ // you can fill with Telethon or Pyrogram string session.
23
+ new Storages.StringSession(''),
24
+ apiHash,
25
+ apiId,
26
+ );
27
+ // handle update
28
+ client.addHandler((update) => {
29
+ console.log(update);
30
+ });
31
+
32
+ // if you already pass the string session, don't fill any arguments in start function, leave it empty.
33
+ client.start({
34
+ botToken: '', // if you want login as bot, you can login as user too.
35
+ /* Remove "botToken" if you want to login as user.
36
+ phoneNumber : async () => {}, // Phone number with international phone code (include plus sign (+)) will be used to login, the return of function must be a string.
37
+ code : async () => {}, // OTP code, the return of function must be a string.
38
+ password : async () => {}, // if you account has 2FA, the return of function must be a string.
39
+ authError : async (error) => {} // when error BadRequest attempt, this function will be running.
40
+ */
41
+ });
42
+ ```
43
+
44
+ ### Exporting Session.
45
+
46
+ For exporting string session, use `client.exportSession()`. It will be return `Promise<string>`.
47
+
48
+ ```typescript
49
+ const exported = await client.exportSession();
50
+ ```
51
+
52
+ ---
53
+
54
+ ## Development Guidelines
55
+
56
+ - Cloning Repository
57
+
58
+ ```bash
59
+ $ git clone https://github.com/tgsnake/core
60
+ ```
61
+
62
+ - Installing Dependencies
63
+
64
+ > Required to use yarn!
65
+
66
+ ```bash
67
+ $ yarn install
68
+ ```
69
+
70
+ - Building TLSchema and Error class
71
+
72
+ ```bash
73
+ $ yarn build:api
74
+ $ yarn build:error
75
+ ```
76
+
77
+ - Testing your app! Create `test` folder and you can create `index.js` file for testing the app. This folder will automatically ignored and not pushing to GitHub.
78
+
79
+ ---
80
+
81
+ ## Notes
82
+
83
+ - This framework is porting of pyrogram for connecting to telegram server. I have dedicated 2 months of my time to complete this framework from scratch. Research after research I do to improve this framework. So big thanks for pyrogram for the source, without that source code, this framework maybe unavailable.
84
+ - For more questions, ask on telegram group ([@tgsnake](https://t.me/tgsnake)) or open github issue.
85
+
86
+ ## GPL v3 License
87
+
88
+ Build with ♥️ by [tgsnake dev](https://t.me/tgsnakechat).
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@armatofik/tgsnake-core",
3
+ "version": "1.13.15",
4
+ "description": "Pure Telegram MTProto library for Javascript or Typescript.",
5
+ "main": "./lib/src/index.js",
6
+ "devDependencies": {
7
+ "@types/node": "22.14.0",
8
+ "deno2node": "1.15.0",
9
+ "prettier": "3.5.3"
10
+ },
11
+ "scripts": {
12
+ "build": "deno2node tsconfig.json",
13
+ "build:license": "node ./generator/license",
14
+ "build:chglog": "node ./generator/chglog",
15
+ "prepare": "yarn build",
16
+ "prettier": "NODE_OPTIONS=--max_old_space_size=4096 prettier -w ."
17
+ },
18
+ "homepage": "https://tgsnake.js.org",
19
+ "keywords": [
20
+ "tgsnake",
21
+ "mtproto",
22
+ "telegram"
23
+ ],
24
+ "bugs": "https://github.com/tgsnake/core/issues",
25
+ "repository": "https://github.com/Armatofik/tgsnake-core",
26
+ "author": "butthx",
27
+ "files": [
28
+ "lib/**/**"
29
+ ],
30
+ "license": "(GPL-3.0 OR LGPL-3.0)",
31
+ "engineStrict": true,
32
+ "engines": {
33
+ "node": ">=12.0.0",
34
+ "npm": ">=6.0.0",
35
+ "yarn": ">=1.0.0"
36
+ },
37
+ "packageManager": "yarn@4.8.1",
38
+ "dependencies": {
39
+ "@tgsnake/log": "latest",
40
+ "async-mutex": "0.5.0",
41
+ "big-integer": "1.6.52",
42
+ "socks": "2.8.4"
43
+ },
44
+ "isBeta": false,
45
+ "isPrivate": false
46
+ }
@@ -0,0 +1,3 @@
1
+ import { Logger } from './platform.node.js';
2
+ declare const log: Logger;
3
+ export { log as Logger };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Logger = void 0;
4
+ const platform_node_js_1 = require("./platform.node.js");
5
+ const log = new platform_node_js_1.Logger({
6
+ name: '@tgsnake/core',
7
+ level: ['debug'],
8
+ });
9
+ exports.Logger = log;
@@ -0,0 +1,19 @@
1
+ export declare class Queue<T> {
2
+ protected _maxsize: number;
3
+ protected _queues: Array<T>;
4
+ protected _possiblePut: boolean | Promise<boolean>;
5
+ protected _resolvePut: {
6
+ (value: boolean): any;
7
+ };
8
+ protected _possibleGet: Promise<boolean>;
9
+ protected _resolveGet: {
10
+ (value: boolean): any;
11
+ };
12
+ constructor(maxsize?: number);
13
+ put(value: T): Promise<void>;
14
+ get(): Promise<T | undefined>;
15
+ get full(): boolean;
16
+ get size(): number;
17
+ get empty(): boolean;
18
+ get maxsize(): number;
19
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Queue = void 0;
4
+ class Queue {
5
+ _maxsize;
6
+ _queues;
7
+ _possiblePut;
8
+ _resolvePut;
9
+ _possibleGet;
10
+ _resolveGet;
11
+ constructor(maxsize = 0) {
12
+ this._maxsize = maxsize;
13
+ this._queues = [];
14
+ this._possiblePut = this._queues.length < maxsize;
15
+ this._resolvePut = (_value) => { };
16
+ this._possibleGet = new Promise((resolve) => {
17
+ this._resolveGet = resolve;
18
+ });
19
+ }
20
+ async put(value) {
21
+ if (this.full)
22
+ await this._possiblePut;
23
+ this._queues.push(value);
24
+ this._resolveGet(true);
25
+ this._possiblePut = new Promise((resolve) => {
26
+ this._resolvePut = resolve;
27
+ });
28
+ }
29
+ async get() {
30
+ if (this.empty)
31
+ await this._possibleGet;
32
+ const value = this._queues.shift();
33
+ this._resolvePut(true);
34
+ this._possibleGet = new Promise((resolve) => {
35
+ this._resolveGet = resolve;
36
+ });
37
+ return value;
38
+ }
39
+ get full() {
40
+ return this.maxsize <= 0 ? false : this.size >= this.maxsize;
41
+ }
42
+ get size() {
43
+ return this._queues.length;
44
+ }
45
+ get empty() {
46
+ return !this.size;
47
+ }
48
+ get maxsize() {
49
+ return this._maxsize;
50
+ }
51
+ }
52
+ exports.Queue = Queue;
@@ -0,0 +1,9 @@
1
+ export interface OnTimeout {
2
+ (timeout: number, index: number): any;
3
+ }
4
+ export declare class Timeout {
5
+ private _task;
6
+ constructor();
7
+ run(task: Promise<any>, time: number, onTimeout?: OnTimeout): Promise<any>;
8
+ clear(): void;
9
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Timeout = void 0;
4
+ const index_js_1 = require("./errors/index.js");
5
+ class Timeout {
6
+ _task = [];
7
+ constructor() { }
8
+ run(task, time, onTimeout) {
9
+ if (time === Infinity)
10
+ return task;
11
+ return new Promise((res, rej) => {
12
+ let index = this._task.length;
13
+ let timeout = setTimeout(() => {
14
+ if (onTimeout) {
15
+ onTimeout(time, index);
16
+ }
17
+ else {
18
+ rej(new index_js_1.TimeoutError(time));
19
+ }
20
+ task.catch(rej).finally(() => {
21
+ return 'Running timeout';
22
+ });
23
+ }, time);
24
+ this._task.push(timeout);
25
+ task
26
+ .then(res)
27
+ .catch(rej)
28
+ .finally(() => {
29
+ clearTimeout(timeout);
30
+ this._task = this._task.filter((t) => !t._destroyed);
31
+ });
32
+ });
33
+ }
34
+ clear() {
35
+ for (let i = 0; i < this._task.length; i++) {
36
+ let task = this._task[i];
37
+ if (!task._destroyed) {
38
+ clearTimeout(task);
39
+ }
40
+ this._task.splice(i, 1);
41
+ }
42
+ }
43
+ }
44
+ exports.Timeout = Timeout;
@@ -0,0 +1,4 @@
1
+ export declare const version: string;
2
+ export declare const isBeta: boolean;
3
+ export declare const isPrivate: boolean;
4
+ export declare function getType(): "Private Beta" | "Beta" | "Private Stable" | "Stable";
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isPrivate = exports.isBeta = exports.version = void 0;
7
+ exports.getType = getType;
8
+ const package_json_1 = __importDefault(require("../package.json"));
9
+ exports.version = package_json_1.default.version;
10
+ exports.isBeta = package_json_1.default.isBeta;
11
+ exports.isPrivate = package_json_1.default.isPrivate;
12
+ function getType() {
13
+ if (exports.isBeta) {
14
+ if (exports.isPrivate) {
15
+ return 'Private Beta';
16
+ }
17
+ return 'Beta';
18
+ }
19
+ if (exports.isPrivate) {
20
+ if (exports.isBeta) {
21
+ return 'Private Beta';
22
+ }
23
+ return 'Private Stable';
24
+ }
25
+ return 'Stable';
26
+ }
@@ -0,0 +1,40 @@
1
+ import type { Client } from './Client.js';
2
+ import { Raw } from '../raw/index.js';
3
+ import * as Errors from '../errors/index.js';
4
+ export interface SigInBot {
5
+ botToken: string | Promise<string>;
6
+ }
7
+ export interface SigInUser {
8
+ phoneNumber: {
9
+ (): Promise<string>;
10
+ };
11
+ password?: {
12
+ (hint: string): Promise<string>;
13
+ };
14
+ recoveryCode?: {
15
+ (): Promise<string>;
16
+ };
17
+ code: {
18
+ (): Promise<string>;
19
+ };
20
+ firstname?: {
21
+ (): Promise<string>;
22
+ };
23
+ lastname?: {
24
+ (): Promise<string>;
25
+ };
26
+ authError?: {
27
+ (error: Errors.Exceptions.BadRequest.BadRequest): void;
28
+ };
29
+ }
30
+ export declare function siginBot(this: Client, botToken: string): Promise<Raw.User | undefined>;
31
+ export declare function siginUser(this: Client, auth: SigInUser): Promise<Raw.User | undefined>;
32
+ export declare function sendCode(this: Client, phoneNumber: string): Promise<Raw.auth.TypeSentCode>;
33
+ export declare function sigin(this: Client, phoneNumber: string, phoneCodeHash: string, phoneCode: string): Promise<Raw.User | Raw.help.TermsOfService | boolean>;
34
+ export declare function recoverPassword(this: Client, code: string): Promise<Raw.User | undefined>;
35
+ export declare function sendRecoveryCode(this: Client): Promise<string>;
36
+ export declare function checkPassword(this: Client, password: string): Promise<Raw.User | undefined>;
37
+ export declare function acceptTOS(this: Client, id: string): Promise<boolean>;
38
+ export declare function getPasswordHint(this: Client): Promise<string>;
39
+ export declare function signup(this: Client, phoneNumber: string, phoneCodeHash: string, firstname: string, lastname?: string): Promise<Raw.User | undefined>;
40
+ export declare function getMe(this: Client): Promise<Raw.users.UserFull>;