rubjs 1.0.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.
- package/README.md +0 -0
- package/package.json +40 -0
- package/rubjs/client.d.ts +34 -0
- package/rubjs/client.js +47 -0
- package/rubjs/crypto/index.d.ts +12 -0
- package/rubjs/crypto/index.js +95 -0
- package/rubjs/index.d.ts +4 -0
- package/rubjs/index.js +11 -0
- package/rubjs/methods/advanced/builder.d.ts +3 -0
- package/rubjs/methods/advanced/builder.js +41 -0
- package/rubjs/methods/advanced/index.d.ts +2 -0
- package/rubjs/methods/advanced/index.js +8 -0
- package/rubjs/methods/auth/index.d.ts +4 -0
- package/rubjs/methods/auth/index.js +12 -0
- package/rubjs/methods/auth/register_device.d.ts +3 -0
- package/rubjs/methods/auth/register_device.js +61 -0
- package/rubjs/methods/auth/send_code.d.ts +4 -0
- package/rubjs/methods/auth/send_code.js +25 -0
- package/rubjs/methods/auth/sign_in.d.ts +4 -0
- package/rubjs/methods/auth/sign_in.js +24 -0
- package/rubjs/methods/index.d.ts +21 -0
- package/rubjs/methods/index.js +40 -0
- package/rubjs/methods/users/get_user_info.d.ts +4 -0
- package/rubjs/methods/users/get_user_info.js +18 -0
- package/rubjs/methods/users/index.d.ts +2 -0
- package/rubjs/methods/users/index.js +8 -0
- package/rubjs/methods/utilities/index.d.ts +3 -0
- package/rubjs/methods/utilities/index.js +10 -0
- package/rubjs/methods/utilities/on_chat_updates.d.ts +4 -0
- package/rubjs/methods/utilities/on_chat_updates.js +17 -0
- package/rubjs/methods/utilities/on_message_updates.d.ts +4 -0
- package/rubjs/methods/utilities/on_message_updates.js +17 -0
- package/rubjs/methods/utilities/on_show_activities.d.ts +4 -0
- package/rubjs/methods/utilities/on_show_activities.js +17 -0
- package/rubjs/methods/utilities/on_show_notifications.d.ts +4 -0
- package/rubjs/methods/utilities/on_show_notifications.js +21 -0
- package/rubjs/methods/utilities/run.d.ts +3 -0
- package/rubjs/methods/utilities/run.js +17 -0
- package/rubjs/methods/utilities/start.d.ts +3 -0
- package/rubjs/methods/utilities/start.js +68 -0
- package/rubjs/network/index.d.ts +29 -0
- package/rubjs/network/index.js +172 -0
- package/rubjs/session/index.d.ts +18 -0
- package/rubjs/session/index.js +57 -0
- package/rubjs/types/chat_updates.d.ts +26 -0
- package/rubjs/types/chat_updates.js +2 -0
- package/rubjs/types/filters_optiom.d.ts +10 -0
- package/rubjs/types/filters_optiom.js +2 -0
- package/rubjs/types/get_user_info.d.ts +63 -0
- package/rubjs/types/get_user_info.js +2 -0
- package/rubjs/types/index.d.ts +9 -0
- package/rubjs/types/index.js +2 -0
- package/rubjs/types/message_update.d.ts +112 -0
- package/rubjs/types/message_update.js +2 -0
- package/rubjs/types/send_code.d.ts +10 -0
- package/rubjs/types/send_code.js +2 -0
- package/rubjs/types/show_activities.d.ts +7 -0
- package/rubjs/types/show_activities.js +2 -0
- package/rubjs/types/show_notifications.d.ts +14 -0
- package/rubjs/types/show_notifications.js +2 -0
- package/rubjs/types/sign_in.d.ts +30 -0
- package/rubjs/types/sign_in.js +2 -0
- package/rubjs/utils/filters.d.ts +26 -0
- package/rubjs/utils/filters.js +72 -0
- package/rubjs/utils/index.d.ts +2 -0
- package/rubjs/utils/index.js +8 -0
package/README.md
ADDED
File without changes
|
package/package.json
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
{
|
2
|
+
"name": "rubjs",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"main": "rubjs/index.js",
|
5
|
+
"types": "rubjs/index.d.ts",
|
6
|
+
"keywords": [
|
7
|
+
"javascript",
|
8
|
+
"Rubika",
|
9
|
+
"library"
|
10
|
+
],
|
11
|
+
"module": "rubjs/index.js",
|
12
|
+
"exports": {
|
13
|
+
"import": "./rubjs/index.js",
|
14
|
+
"require": "./rubjs/index.js",
|
15
|
+
"types": "./rubjs/index.d.ts"
|
16
|
+
},
|
17
|
+
"author": "Hadi Rostami",
|
18
|
+
"license": "MIT",
|
19
|
+
"type": "commonjs",
|
20
|
+
"description": "A library for Rubika in JavaScript.",
|
21
|
+
"scripts": {
|
22
|
+
"build": "tsc",
|
23
|
+
"dev": "tsc --watch"
|
24
|
+
},
|
25
|
+
"dependencies": {
|
26
|
+
"axios": "^1.7.9",
|
27
|
+
"better-sqlite3": "^11.8.1",
|
28
|
+
"input": "^1.0.1",
|
29
|
+
"node-rsa": "^1.1.1",
|
30
|
+
"ws": "^8.18.0"
|
31
|
+
},
|
32
|
+
"devDependencies": {
|
33
|
+
"@types/node": "^22.13.1",
|
34
|
+
"typescript": "^5.7.3"
|
35
|
+
},
|
36
|
+
"files": [
|
37
|
+
"rubjs/",
|
38
|
+
"README.md"
|
39
|
+
]
|
40
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import Methods from "./methods";
|
2
|
+
import Network from "./network";
|
3
|
+
import SQLiteSession from "./session";
|
4
|
+
interface Platform {
|
5
|
+
app_name: string;
|
6
|
+
app_version: string;
|
7
|
+
platform: string;
|
8
|
+
package: string;
|
9
|
+
lang_code: string;
|
10
|
+
}
|
11
|
+
type TypeUpdate = "show_activities" | "chat_updates" | "message_updates" | "show_notifications";
|
12
|
+
type PlatformType = "Web" | "Android";
|
13
|
+
declare class Client extends Methods {
|
14
|
+
defaultPlatform: Platform;
|
15
|
+
apiVersion: string;
|
16
|
+
userAgent: string;
|
17
|
+
key: Buffer<ArrayBuffer>;
|
18
|
+
decode_auth: string;
|
19
|
+
auth: string | null;
|
20
|
+
timeout: number;
|
21
|
+
network: Network;
|
22
|
+
privateKey: string | null;
|
23
|
+
sessionFile: string;
|
24
|
+
platform: PlatformType;
|
25
|
+
userGuid: string | null;
|
26
|
+
sessionDb: SQLiteSession;
|
27
|
+
eventHandlers: {
|
28
|
+
callback: Function;
|
29
|
+
filters: ((msg: any) => boolean)[];
|
30
|
+
updateType: TypeUpdate;
|
31
|
+
}[];
|
32
|
+
constructor(sessionFile: string, timeout?: number, platform?: PlatformType);
|
33
|
+
}
|
34
|
+
export default Client;
|
package/rubjs/client.js
ADDED
@@ -0,0 +1,47 @@
|
|
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
|
+
const methods_1 = __importDefault(require("./methods"));
|
7
|
+
const network_1 = __importDefault(require("./network"));
|
8
|
+
const session_1 = __importDefault(require("./session"));
|
9
|
+
class Client extends methods_1.default {
|
10
|
+
constructor(sessionFile, timeout, platform = "Web") {
|
11
|
+
super();
|
12
|
+
this.defaultPlatform = {
|
13
|
+
app_name: "Main",
|
14
|
+
app_version: "4.4.9",
|
15
|
+
platform: "Web",
|
16
|
+
package: "web.rubika.ir",
|
17
|
+
lang_code: "fa",
|
18
|
+
};
|
19
|
+
this.apiVersion = "6";
|
20
|
+
this.userAgent = `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36`;
|
21
|
+
if (platform.toLowerCase() === "android") {
|
22
|
+
this.defaultPlatform.platform = "Android";
|
23
|
+
this.defaultPlatform["package"] = "app.rbmain.a";
|
24
|
+
this.defaultPlatform["app_version"] = "3.6.4";
|
25
|
+
}
|
26
|
+
this.sessionFile = sessionFile;
|
27
|
+
this.userGuid = null;
|
28
|
+
this.timeout = timeout !== null && timeout !== void 0 ? timeout : 0;
|
29
|
+
this.eventHandlers = [];
|
30
|
+
this.platform = platform;
|
31
|
+
this.sessionDb = new session_1.default(sessionFile);
|
32
|
+
this.network = new network_1.default(this);
|
33
|
+
this.auth = null;
|
34
|
+
this.privateKey = null;
|
35
|
+
this.eventHandlers = [];
|
36
|
+
const DBInformation = this.sessionDb.getSession();
|
37
|
+
if (DBInformation) {
|
38
|
+
this.auth = DBInformation.auth;
|
39
|
+
this.userGuid = DBInformation.guid;
|
40
|
+
this.privateKey = DBInformation.private_key;
|
41
|
+
if (typeof DBInformation.agent === "string")
|
42
|
+
this.userAgent = DBInformation.agent || this.userAgent;
|
43
|
+
}
|
44
|
+
this.start();
|
45
|
+
}
|
46
|
+
}
|
47
|
+
exports.default = Client;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
declare class Crypto {
|
2
|
+
static AES_IV: Buffer<ArrayBuffer>;
|
3
|
+
static decode_auth: (auth: string) => string;
|
4
|
+
static passphrase(auth: string): string;
|
5
|
+
static secret(length: number): string;
|
6
|
+
static decrypt(data_enc: string, key: Buffer<ArrayBufferLike>): string;
|
7
|
+
static encrypt(data: string, key: Buffer<ArrayBufferLike>): string;
|
8
|
+
static sign(data_enc: string, privateKey: string): string;
|
9
|
+
static createKeys(): any[];
|
10
|
+
static decrypt_RSA_OAEP(private_key: string, data: string): any;
|
11
|
+
}
|
12
|
+
export default Crypto;
|
@@ -0,0 +1,95 @@
|
|
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
|
+
const node_rsa_1 = __importDefault(require("node-rsa"));
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
8
|
+
class Crypto {
|
9
|
+
static passphrase(auth) {
|
10
|
+
if (auth.length !== 32) {
|
11
|
+
throw new Error("auth length should be 32 digits");
|
12
|
+
}
|
13
|
+
const resultList = [];
|
14
|
+
const chunks = auth.match(/.{8}/g);
|
15
|
+
if (!chunks || chunks.length !== 4) {
|
16
|
+
throw new Error("Invalid auth format");
|
17
|
+
}
|
18
|
+
const combined = chunks[2] + chunks[0] + chunks[3] + chunks[1];
|
19
|
+
for (const character of combined) {
|
20
|
+
const newChar = String.fromCharCode(((character.charCodeAt(0) - 97 + 9) % 26) + 97);
|
21
|
+
resultList.push(newChar);
|
22
|
+
}
|
23
|
+
return resultList.join("");
|
24
|
+
}
|
25
|
+
static secret(length) {
|
26
|
+
if (length <= 0 || !Number.isInteger(length)) {
|
27
|
+
throw new Error("Length must be a positive integer");
|
28
|
+
}
|
29
|
+
const characters = "abcdefghijklmnopqrstuvwxyz";
|
30
|
+
let secret = "";
|
31
|
+
for (let i = 0; i < length; i++) {
|
32
|
+
const randomIndex = Math.floor(Math.random() * characters.length);
|
33
|
+
secret += characters[randomIndex];
|
34
|
+
}
|
35
|
+
return secret;
|
36
|
+
}
|
37
|
+
static decrypt(data_enc, key) {
|
38
|
+
const decipher = crypto_1.default.createDecipheriv("aes-256-cbc", key, this.AES_IV);
|
39
|
+
let decrypted = decipher.update(data_enc, "base64", "utf8");
|
40
|
+
decrypted += decipher.final("utf8");
|
41
|
+
return decrypted;
|
42
|
+
}
|
43
|
+
static encrypt(data, key) {
|
44
|
+
const cipher = crypto_1.default.createCipheriv("aes-256-cbc", key, this.AES_IV);
|
45
|
+
let encrypted = cipher.update(data, "utf8", "base64");
|
46
|
+
encrypted += cipher.final("base64");
|
47
|
+
return encrypted;
|
48
|
+
}
|
49
|
+
static sign(data_enc, privateKey) {
|
50
|
+
if (!privateKey) {
|
51
|
+
throw new Error("Private key is not defined");
|
52
|
+
}
|
53
|
+
const sign = crypto_1.default.createSign("SHA256");
|
54
|
+
sign.update(data_enc);
|
55
|
+
sign.end();
|
56
|
+
const signature = sign.sign(privateKey, "base64");
|
57
|
+
return signature;
|
58
|
+
}
|
59
|
+
static createKeys() {
|
60
|
+
const keyPair = new node_rsa_1.default({
|
61
|
+
b: 1024,
|
62
|
+
});
|
63
|
+
let publicKey = Crypto.decode_auth(Buffer.from(keyPair.exportKey("pkcs1-public-pem"), "binary").toString("base64"));
|
64
|
+
let privateKey = keyPair.exportKey("pkcs1-private-pem");
|
65
|
+
return [publicKey, privateKey];
|
66
|
+
}
|
67
|
+
static decrypt_RSA_OAEP(private_key, data) {
|
68
|
+
const keyPair = new node_rsa_1.default(private_key);
|
69
|
+
const decrypted = keyPair.decrypt(data, "utf8");
|
70
|
+
return decrypted;
|
71
|
+
}
|
72
|
+
}
|
73
|
+
Crypto.AES_IV = Buffer.alloc(16, 0);
|
74
|
+
Crypto.decode_auth = (auth) => {
|
75
|
+
let n = "";
|
76
|
+
const lowercase = "abcdefghijklmnopqrstuvwxyz";
|
77
|
+
const uppercase = lowercase.toUpperCase();
|
78
|
+
const digits = "0123456789";
|
79
|
+
for (const s of auth) {
|
80
|
+
if (lowercase.includes(s)) {
|
81
|
+
n += String.fromCharCode(((32 - (s.charCodeAt(0) - 97)) % 26) + 97);
|
82
|
+
}
|
83
|
+
else if (uppercase.includes(s)) {
|
84
|
+
n += String.fromCharCode(((29 - (s.charCodeAt(0) - 65)) % 26) + 65);
|
85
|
+
}
|
86
|
+
else if (digits.includes(s)) {
|
87
|
+
n += String.fromCharCode(((13 - (s.charCodeAt(0) - 48)) % 10) + 48);
|
88
|
+
}
|
89
|
+
else {
|
90
|
+
n += s;
|
91
|
+
}
|
92
|
+
}
|
93
|
+
return n;
|
94
|
+
};
|
95
|
+
exports.default = Crypto;
|
package/rubjs/index.d.ts
ADDED
package/rubjs/index.js
ADDED
@@ -0,0 +1,11 @@
|
|
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.Client = exports.Filters = void 0;
|
7
|
+
const client_1 = __importDefault(require("./client"));
|
8
|
+
exports.Client = client_1.default;
|
9
|
+
const utils_1 = require("./utils");
|
10
|
+
Object.defineProperty(exports, "Filters", { enumerable: true, get: function () { return utils_1.Filters; } });
|
11
|
+
exports.default = client_1.default;
|
@@ -0,0 +1,41 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
const crypto_1 = __importDefault(require("../../crypto"));
|
16
|
+
function builder(name_1, input_1) {
|
17
|
+
return __awaiter(this, arguments, void 0, function* (name, input, tmp_session = false) {
|
18
|
+
if (!this.auth)
|
19
|
+
this.auth = crypto_1.default.secret(32);
|
20
|
+
if (!this.key)
|
21
|
+
this.key = Buffer.from(crypto_1.default.passphrase(this.auth), "utf8");
|
22
|
+
let result = yield this.network.send({
|
23
|
+
input,
|
24
|
+
tmp_session,
|
25
|
+
method: name,
|
26
|
+
});
|
27
|
+
if (result) {
|
28
|
+
const data_enc = result.data_enc;
|
29
|
+
if (data_enc) {
|
30
|
+
const decrypted = crypto_1.default.decrypt(data_enc, this.key);
|
31
|
+
result = JSON.parse(decrypted);
|
32
|
+
}
|
33
|
+
const status = result.status;
|
34
|
+
const status_det = result.status_det;
|
35
|
+
if (status == "OK" && status_det == "OK") {
|
36
|
+
return result.data;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
});
|
40
|
+
}
|
41
|
+
exports.default = builder;
|
@@ -0,0 +1,8 @@
|
|
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.builder = void 0;
|
7
|
+
const builder_1 = __importDefault(require("./builder"));
|
8
|
+
exports.builder = builder_1.default;
|
@@ -0,0 +1,12 @@
|
|
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.sign_in = exports.send_code = exports.register_device = void 0;
|
7
|
+
const register_device_1 = __importDefault(require("./register_device"));
|
8
|
+
exports.register_device = register_device_1.default;
|
9
|
+
const send_code_1 = __importDefault(require("./send_code"));
|
10
|
+
exports.send_code = send_code_1.default;
|
11
|
+
const sign_in_1 = __importDefault(require("./sign_in"));
|
12
|
+
exports.sign_in = sign_in_1.default;
|
@@ -0,0 +1,61 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
const systemVersions = {
|
13
|
+
"Windows NT 10.0": "Windows 10",
|
14
|
+
"Windows NT 6.2": "Windows 8",
|
15
|
+
"Windows NT 6.1": "Windows 7",
|
16
|
+
"Windows NT 6.0": "Windows Vista",
|
17
|
+
"Windows NT 5.1": "windows XP",
|
18
|
+
"Windows NT 5.0": "Windows 2000",
|
19
|
+
Mac: "Mac/iOS",
|
20
|
+
X11: "UNIX",
|
21
|
+
Linux: "Linux",
|
22
|
+
};
|
23
|
+
function getBrowser(userAgent, langCode, appVersion, ...args) {
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
25
|
+
var _a;
|
26
|
+
const deviceModelMatch = userAgent
|
27
|
+
.toLowerCase()
|
28
|
+
.match(/(opera|chrome|safari|firefox|msie|trident)\/(\d+)/);
|
29
|
+
let deviceModel = "Unknown";
|
30
|
+
if (!deviceModelMatch) {
|
31
|
+
console.warn(`Cannot parse user-agent (${userAgent})`);
|
32
|
+
}
|
33
|
+
else {
|
34
|
+
deviceModel = `${deviceModelMatch[1]} ${deviceModelMatch[2]}`;
|
35
|
+
}
|
36
|
+
let systemVersion = "Unknown";
|
37
|
+
for (const [key, value] of Object.entries(systemVersions)) {
|
38
|
+
if (userAgent.includes(key)) {
|
39
|
+
systemVersion = value;
|
40
|
+
break;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
const deviceHash = "2" + (((_a = userAgent.match(/\d+/g)) === null || _a === void 0 ? void 0 : _a.join("")) || "");
|
44
|
+
return {
|
45
|
+
token: "",
|
46
|
+
lang_code: langCode,
|
47
|
+
token_type: "Web",
|
48
|
+
app_version: `WB_${appVersion}`,
|
49
|
+
system_version: systemVersion,
|
50
|
+
device_model: deviceModel.charAt(0).toUpperCase() + deviceModel.slice(1),
|
51
|
+
device_hash: deviceHash,
|
52
|
+
};
|
53
|
+
});
|
54
|
+
}
|
55
|
+
function register_device() {
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
57
|
+
const result = yield this.builder("registerDevice", yield getBrowser(this.userAgent, this.defaultPlatform.lang_code, this.defaultPlatform.app_version));
|
58
|
+
return result;
|
59
|
+
});
|
60
|
+
}
|
61
|
+
exports.default = register_device;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
function send_code(phone_number_1) {
|
13
|
+
return __awaiter(this, arguments, void 0, function* (phone_number, pass_key = null, send_type = "SMS") {
|
14
|
+
if (!["SMS", "Internal"].includes(send_type))
|
15
|
+
throw new Error("send_type can only be `SMS` or `Internal`.");
|
16
|
+
const data = {
|
17
|
+
phone_number,
|
18
|
+
pass_key,
|
19
|
+
send_type,
|
20
|
+
};
|
21
|
+
const result = yield this.builder("sendCode", data, true);
|
22
|
+
return result;
|
23
|
+
});
|
24
|
+
}
|
25
|
+
exports.default = send_code;
|
@@ -0,0 +1,24 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
function sign_in(phone_code, phone_number, phone_code_hash, public_key) {
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
14
|
+
const data = {
|
15
|
+
phone_code,
|
16
|
+
phone_number,
|
17
|
+
phone_code_hash,
|
18
|
+
public_key,
|
19
|
+
};
|
20
|
+
const result = yield this.builder("signIn", data, true);
|
21
|
+
return result;
|
22
|
+
});
|
23
|
+
}
|
24
|
+
exports.default = sign_in;
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import Client from "..";
|
2
|
+
import { UserInfo, SendCode, SignIn, MessageUpdate, ChatUpdates, ShowNotifications, ShowActivities } from "../types";
|
3
|
+
declare class Methods {
|
4
|
+
private registerHandler;
|
5
|
+
on_message_updates(callback: (message: MessageUpdate) => void): void;
|
6
|
+
on_message_updates(filters: ((msg: MessageUpdate) => boolean)[], callback: (message: MessageUpdate) => void): void;
|
7
|
+
on_chat_updates(callback: (message: ChatUpdates) => void): void;
|
8
|
+
on_chat_updates(filters: ((msg: ChatUpdates) => boolean)[], callback: (message: ChatUpdates) => void): void;
|
9
|
+
on_show_activities(callback: (message: ShowActivities) => void): void;
|
10
|
+
on_show_activities(filters: ((msg: ShowActivities) => boolean)[], callback: (message: ShowActivities) => void): void;
|
11
|
+
on_show_notifications(callback: (message: ShowNotifications) => void): void;
|
12
|
+
on_show_notifications(filters: ((msg: ShowNotifications) => boolean)[], callback: (message: ShowNotifications) => void): void;
|
13
|
+
run: (this: Client) => Promise<void>;
|
14
|
+
start: (this: Client) => Promise<void>;
|
15
|
+
get_user_info: (this: Client) => Promise<UserInfo>;
|
16
|
+
register_device: (this: Client) => Promise<void>;
|
17
|
+
send_code: (this: Client, phone_number: string, pass_key?: string, send_type?: string) => Promise<SendCode>;
|
18
|
+
sign_in: (this: Client, phone_code: string, phone_number: string, phone_code_hash: string, public_key: string) => Promise<SignIn>;
|
19
|
+
builder: (this: Client, name: string, input: object, tmp_session?: boolean) => Promise<any>;
|
20
|
+
}
|
21
|
+
export default Methods;
|
@@ -0,0 +1,40 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const utilities_1 = require("./utilities");
|
4
|
+
const users_1 = require("./users");
|
5
|
+
const advanced_1 = require("./advanced");
|
6
|
+
const auth_1 = require("./auth");
|
7
|
+
class Methods {
|
8
|
+
registerHandler(updateType, arg1, arg2) {
|
9
|
+
let filters = [];
|
10
|
+
let callback;
|
11
|
+
if (typeof arg1 === "function") {
|
12
|
+
callback = arg1;
|
13
|
+
}
|
14
|
+
else {
|
15
|
+
filters = arg1;
|
16
|
+
callback = arg2;
|
17
|
+
}
|
18
|
+
this.eventHandlers.push({ callback, filters, updateType });
|
19
|
+
}
|
20
|
+
on_message_updates(arg1, arg2) {
|
21
|
+
this.registerHandler("message_updates", arg1, arg2);
|
22
|
+
}
|
23
|
+
on_chat_updates(arg1, arg2) {
|
24
|
+
this.registerHandler("chat_updates", arg1, arg2);
|
25
|
+
}
|
26
|
+
on_show_activities(arg1, arg2) {
|
27
|
+
this.registerHandler("show_activities", arg1, arg2);
|
28
|
+
}
|
29
|
+
on_show_notifications(arg1, arg2) {
|
30
|
+
this.registerHandler("show_notifications", arg1, arg2);
|
31
|
+
}
|
32
|
+
}
|
33
|
+
Methods.prototype.run = utilities_1.run;
|
34
|
+
Methods.prototype.start = utilities_1.start;
|
35
|
+
Methods.prototype.get_user_info = users_1.get_user_info;
|
36
|
+
Methods.prototype.builder = advanced_1.builder;
|
37
|
+
Methods.prototype.register_device = auth_1.register_device;
|
38
|
+
Methods.prototype.send_code = auth_1.send_code;
|
39
|
+
Methods.prototype.sign_in = auth_1.sign_in;
|
40
|
+
exports.default = Methods;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
function get_user_info() {
|
13
|
+
return __awaiter(this, arguments, void 0, function* (user_guid = null) {
|
14
|
+
const result = yield this.builder("getUserInfo", user_guid ? { user_guid } : {}, this.auth ? false : true);
|
15
|
+
return result;
|
16
|
+
});
|
17
|
+
}
|
18
|
+
exports.default = get_user_info;
|
@@ -0,0 +1,8 @@
|
|
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.get_user_info = void 0;
|
7
|
+
const get_user_info_1 = __importDefault(require("./get_user_info"));
|
8
|
+
exports.get_user_info = get_user_info_1.default;
|
@@ -0,0 +1,10 @@
|
|
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.run = exports.start = void 0;
|
7
|
+
const start_1 = __importDefault(require("./start"));
|
8
|
+
exports.start = start_1.default;
|
9
|
+
const run_1 = __importDefault(require("./run"));
|
10
|
+
exports.run = run_1.default;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
function on_chat_updates(filters, callback) {
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
14
|
+
this.eventHandlers.push({ callback, filters, updateType: "chat_updates" });
|
15
|
+
});
|
16
|
+
}
|
17
|
+
exports.default = on_chat_updates;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
function on_message_updates(filters, callback) {
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
14
|
+
this.eventHandlers.push({ callback, filters, updateType: "message_updates" });
|
15
|
+
});
|
16
|
+
}
|
17
|
+
exports.default = on_message_updates;
|