@lazyneoaz/nkxchat 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/LICENSE +3 -0
- package/README.md +199 -0
- package/examples/login-with-cookies.js +102 -0
- package/examples/verify.js +70 -0
- package/index.js +2 -0
- package/package.json +84 -0
- package/src/apis/addExternalModule.js +24 -0
- package/src/apis/addUserToGroup.js +108 -0
- package/src/apis/changeAdminStatus.js +148 -0
- package/src/apis/changeArchivedStatus.js +61 -0
- package/src/apis/changeAvatar.js +103 -0
- package/src/apis/changeBio.js +69 -0
- package/src/apis/changeBlockedStatus.js +54 -0
- package/src/apis/changeGroupImage.js +136 -0
- package/src/apis/changeThreadColor.js +116 -0
- package/src/apis/changeThreadEmoji.js +53 -0
- package/src/apis/comment.js +207 -0
- package/src/apis/createAITheme.js +129 -0
- package/src/apis/createNewGroup.js +79 -0
- package/src/apis/createPoll.js +73 -0
- package/src/apis/deleteMessage.js +44 -0
- package/src/apis/deleteThread.js +52 -0
- package/src/apis/editMessage.js +70 -0
- package/src/apis/emoji.js +124 -0
- package/src/apis/enableAutoSaveAppState.js +69 -0
- package/src/apis/fetchThemeData.js +113 -0
- package/src/apis/follow.js +81 -0
- package/src/apis/forwardAttachment.js +178 -0
- package/src/apis/forwardMessage.js +52 -0
- package/src/apis/friend.js +243 -0
- package/src/apis/gcmember.js +122 -0
- package/src/apis/gcname.js +123 -0
- package/src/apis/gcrule.js +119 -0
- package/src/apis/getAccess.js +111 -0
- package/src/apis/getBotInfo.js +88 -0
- package/src/apis/getBotInitialData.js +43 -0
- package/src/apis/getEmojiUrl.js +40 -0
- package/src/apis/getFriendsList.js +79 -0
- package/src/apis/getMessage.js +423 -0
- package/src/apis/getTheme.js +123 -0
- package/src/apis/getThemeInfo.js +116 -0
- package/src/apis/getThemePictures.js +87 -0
- package/src/apis/getThreadColors.js +119 -0
- package/src/apis/getThreadHistory.js +239 -0
- package/src/apis/getThreadInfo.js +267 -0
- package/src/apis/getThreadList.js +232 -0
- package/src/apis/getThreadPictures.js +58 -0
- package/src/apis/getUserID.js +117 -0
- package/src/apis/getUserInfo.js +513 -0
- package/src/apis/getUserInfoV2.js +146 -0
- package/src/apis/handleFriendRequest.js +66 -0
- package/src/apis/handleMessageRequest.js +50 -0
- package/src/apis/httpGet.js +63 -0
- package/src/apis/httpPost.js +89 -0
- package/src/apis/httpPostFormData.js +69 -0
- package/src/apis/listenMqtt.js +924 -0
- package/src/apis/listenSpeed.js +178 -0
- package/src/apis/logout.js +63 -0
- package/src/apis/markAsDelivered.js +47 -0
- package/src/apis/markAsRead.js +95 -0
- package/src/apis/markAsReadAll.js +40 -0
- package/src/apis/markAsSeen.js +70 -0
- package/src/apis/mqttDeltaValue.js +252 -0
- package/src/apis/muteThread.js +45 -0
- package/src/apis/nickname.js +132 -0
- package/src/apis/notes.js +163 -0
- package/src/apis/pinMessage.js +150 -0
- package/src/apis/produceMetaTheme.js +160 -0
- package/src/apis/realtime.js +182 -0
- package/src/apis/refreshFb_dtsg.js +94 -0
- package/src/apis/removeUserFromGroup.js +117 -0
- package/src/apis/resolvePhotoUrl.js +58 -0
- package/src/apis/searchForThread.js +154 -0
- package/src/apis/sendEffect.js +306 -0
- package/src/apis/sendMessage.js +353 -0
- package/src/apis/sendMessageMqtt.js +255 -0
- package/src/apis/sendTypingIndicator.js +40 -0
- package/src/apis/setMessageReaction.js +27 -0
- package/src/apis/setMessageReactionMqtt.js +61 -0
- package/src/apis/setPostReaction.js +118 -0
- package/src/apis/setThreadTheme.js +210 -0
- package/src/apis/setThreadThemeMqtt.js +94 -0
- package/src/apis/setTitle.js +26 -0
- package/src/apis/share.js +106 -0
- package/src/apis/shareContact.js +66 -0
- package/src/apis/stickers.js +257 -0
- package/src/apis/story.js +181 -0
- package/src/apis/theme.js +233 -0
- package/src/apis/unfriend.js +47 -0
- package/src/apis/unsendMessage.js +17 -0
- package/src/apis/uploadAttachment.js +87 -0
- package/src/database/appStateBackup.js +189 -0
- package/src/database/models/index.js +56 -0
- package/src/database/models/thread.js +31 -0
- package/src/database/models/user.js +32 -0
- package/src/database/threadData.js +101 -0
- package/src/database/userData.js +90 -0
- package/src/engine/client.js +92 -0
- package/src/engine/models/buildAPI.js +118 -0
- package/src/engine/models/loginHelper.js +492 -0
- package/src/engine/models/setOptions.js +88 -0
- package/src/types/index.d.ts +498 -0
- package/src/utils/antiSuspension.js +516 -0
- package/src/utils/auth-helpers.js +149 -0
- package/src/utils/autoReLogin.js +237 -0
- package/src/utils/axios.js +368 -0
- package/src/utils/cache.js +54 -0
- package/src/utils/clients.js +279 -0
- package/src/utils/constants.js +525 -0
- package/src/utils/formatters/data/formatAttachment.js +370 -0
- package/src/utils/formatters/data/formatDelta.js +109 -0
- package/src/utils/formatters/index.js +159 -0
- package/src/utils/formatters/value/formatCookie.js +91 -0
- package/src/utils/formatters/value/formatDate.js +36 -0
- package/src/utils/formatters/value/formatID.js +16 -0
- package/src/utils/formatters.js +1369 -0
- package/src/utils/headers.js +235 -0
- package/src/utils/index.js +152 -0
- package/src/utils/monitoring.js +333 -0
- package/src/utils/rateLimiter.js +251 -0
- package/src/utils/tokenRefresh.js +285 -0
- package/src/utils/user-agents.js +238 -0
- package/src/utils/validation.js +157 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require("../utils");
|
|
4
|
+
const setOptionsModel = require('./models/setOptions');
|
|
5
|
+
const buildAPIModel = require('./models/buildAPI');
|
|
6
|
+
const loginHelperModel = require('./models/loginHelper');
|
|
7
|
+
|
|
8
|
+
let globalOptions = {};
|
|
9
|
+
let ctx = null;
|
|
10
|
+
let defaultFuncs = null;
|
|
11
|
+
let api = null;
|
|
12
|
+
|
|
13
|
+
const fbLink = (ext) => ("https://www.facebook.com" + (ext ? '/' + ext : ''));
|
|
14
|
+
const ERROR_RETRIEVING = "Error retrieving userID. This can be caused by many factors, including being blocked by Facebook for logging in from an unknown location. Try logging in with a browser to verify.";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Initiates the login process for a Facebook account.
|
|
18
|
+
*
|
|
19
|
+
* @param {object} credentials The user's login credentials (e.g., email/password or appState cookies).
|
|
20
|
+
* @param {object} [options={}] Optional login configurations.
|
|
21
|
+
* @param {function} [callback] Optional callback function. If omitted, returns a Promise.
|
|
22
|
+
* @returns {Promise|void} Returns Promise if no callback provided, otherwise void.
|
|
23
|
+
*/
|
|
24
|
+
async function login(credentials, options, callback) {
|
|
25
|
+
if (typeof options === "function") {
|
|
26
|
+
callback = options;
|
|
27
|
+
options = {};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let promiseCallback = null;
|
|
31
|
+
let rejectFunc = null;
|
|
32
|
+
let resolveFunc = null;
|
|
33
|
+
let returnPromise = null;
|
|
34
|
+
|
|
35
|
+
if (typeof callback !== "function") {
|
|
36
|
+
returnPromise = new Promise(function (resolve, reject) {
|
|
37
|
+
resolveFunc = resolve;
|
|
38
|
+
rejectFunc = reject;
|
|
39
|
+
});
|
|
40
|
+
promiseCallback = function (error, api) {
|
|
41
|
+
if (error) return rejectFunc(error);
|
|
42
|
+
return resolveFunc(api);
|
|
43
|
+
};
|
|
44
|
+
callback = promiseCallback;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if ('logging' in options) {
|
|
48
|
+
utils.logOptions(options.logging);
|
|
49
|
+
}
|
|
50
|
+
const defaultOptions = {
|
|
51
|
+
selfListen: false,
|
|
52
|
+
listenEvents: true,
|
|
53
|
+
listenTyping: false,
|
|
54
|
+
simulateTyping: true,
|
|
55
|
+
updatePresence: false,
|
|
56
|
+
forceLogin: false,
|
|
57
|
+
autoMarkDelivery: false,
|
|
58
|
+
autoMarkRead: true,
|
|
59
|
+
autoReconnect: true,
|
|
60
|
+
online: true,
|
|
61
|
+
emitReady: false,
|
|
62
|
+
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36",
|
|
63
|
+
};
|
|
64
|
+
Object.assign(globalOptions, defaultOptions, options);
|
|
65
|
+
|
|
66
|
+
await setOptionsModel(globalOptions, options);
|
|
67
|
+
|
|
68
|
+
loginHelperModel(
|
|
69
|
+
credentials,
|
|
70
|
+
globalOptions,
|
|
71
|
+
(loginError, loginApi) => {
|
|
72
|
+
if (loginError) {
|
|
73
|
+
return callback(loginError);
|
|
74
|
+
}
|
|
75
|
+
api = loginApi;
|
|
76
|
+
ctx = loginApi.ctx;
|
|
77
|
+
defaultFuncs = loginApi.defaultFuncs;
|
|
78
|
+
return callback(null, loginApi);
|
|
79
|
+
},
|
|
80
|
+
setOptionsModel,
|
|
81
|
+
buildAPIModel,
|
|
82
|
+
api,
|
|
83
|
+
fbLink,
|
|
84
|
+
ERROR_RETRIEVING
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
return returnPromise;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
module.exports = {
|
|
91
|
+
login
|
|
92
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const EventEmitter = require('events');
|
|
4
|
+
const utils = require('../../utils');
|
|
5
|
+
const SimpleCache = require('../../utils/cache');
|
|
6
|
+
const { globalValidator } = require('../../utils/validation');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Builds the core API context and default functions after successful login.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} html The HTML body from the initial Facebook page.
|
|
12
|
+
* @param {object} jar The cookie jar.
|
|
13
|
+
* @param {Array<object>} netData Network data extracted from the HTML.
|
|
14
|
+
* @param {object} globalOptions The global options object.
|
|
15
|
+
* @param {function} fbLinkFunc A function to generate Facebook links.
|
|
16
|
+
* @param {string} errorRetrievingMsg The error message for retrieving user ID.
|
|
17
|
+
* @returns {Array<object>} An array containing [ctx, defaultFuncs, {}].
|
|
18
|
+
*/
|
|
19
|
+
async function buildAPI(html, jar, netData, globalOptions, fbLinkFunc, errorRetrievingMsg) {
|
|
20
|
+
let userID;
|
|
21
|
+
const cookies = jar.getCookiesSync(fbLinkFunc());
|
|
22
|
+
const primaryProfile = cookies.find((val) => val.cookieString().startsWith("c_user="));
|
|
23
|
+
const secondaryProfile = cookies.find((val) => val.cookieString().startsWith("i_user="));
|
|
24
|
+
if (!primaryProfile && !secondaryProfile) {
|
|
25
|
+
throw new Error(errorRetrievingMsg);
|
|
26
|
+
}
|
|
27
|
+
userID = secondaryProfile?.cookieString().split("=")[1] || primaryProfile.cookieString().split("=")[1];
|
|
28
|
+
|
|
29
|
+
const findConfig = (key) => {
|
|
30
|
+
for (const scriptData of netData) {
|
|
31
|
+
if (scriptData.require) {
|
|
32
|
+
for (const req of scriptData.require) {
|
|
33
|
+
if (Array.isArray(req) && req[0] === key && req[2]) {
|
|
34
|
+
return req[2];
|
|
35
|
+
}
|
|
36
|
+
if (Array.isArray(req) && req[3] && req[3][0] && req[3][0].__bbox && req[3][0].__bbox.define) {
|
|
37
|
+
for (const def of req[3][0].__bbox.define) {
|
|
38
|
+
if (Array.isArray(def) && def[0].endsWith(key) && def[2]) {
|
|
39
|
+
return def[2];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const dtsgData = findConfig("DTSGInitialData");
|
|
50
|
+
const dtsg = dtsgData ? dtsgData.token : utils.getFrom(html, '"token":"', '"');
|
|
51
|
+
|
|
52
|
+
const lsdData = findConfig("LSD");
|
|
53
|
+
const lsd = lsdData ? lsdData.token : utils.getFrom(html, '"LSD",[],{"token":"', '"');
|
|
54
|
+
|
|
55
|
+
const dtsgResult = {
|
|
56
|
+
fb_dtsg: dtsg,
|
|
57
|
+
jazoest: `2${Array.from(dtsg).reduce((a, b) => a + b.charCodeAt(0), '')}`,
|
|
58
|
+
lsd: lsd
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const clientIDData = findConfig("MqttWebDeviceID");
|
|
62
|
+
const clientID = clientIDData ? clientIDData.clientID : undefined;
|
|
63
|
+
|
|
64
|
+
const mqttConfigData = findConfig("MqttWebConfig");
|
|
65
|
+
const mqttAppID = mqttConfigData ? mqttConfigData.appID : undefined;
|
|
66
|
+
|
|
67
|
+
const currentUserData = findConfig("CurrentUserInitialData");
|
|
68
|
+
const userAppID = currentUserData ? currentUserData.APP_ID : undefined;
|
|
69
|
+
|
|
70
|
+
let primaryAppID = userAppID || mqttAppID;
|
|
71
|
+
|
|
72
|
+
let mqttEndpoint = mqttConfigData ? mqttConfigData.endpoint : undefined;
|
|
73
|
+
|
|
74
|
+
let region = mqttEndpoint ? new URL(mqttEndpoint).searchParams.get("region")?.toUpperCase() : undefined;
|
|
75
|
+
const irisSeqIDMatch = html.match(/irisSeqID:"(.+?)"/);
|
|
76
|
+
const irisSeqID = irisSeqIDMatch ? irisSeqIDMatch[1] : null;
|
|
77
|
+
if (globalOptions.bypassRegion && mqttEndpoint) {
|
|
78
|
+
const currentEndpoint = new URL(mqttEndpoint);
|
|
79
|
+
currentEndpoint.searchParams.set('region', globalOptions.bypassRegion.toLowerCase());
|
|
80
|
+
mqttEndpoint = currentEndpoint.toString();
|
|
81
|
+
region = globalOptions.bypassRegion.toUpperCase();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const emitter = new EventEmitter();
|
|
85
|
+
emitter.setMaxListeners(50);
|
|
86
|
+
|
|
87
|
+
const ctx = {
|
|
88
|
+
userID,
|
|
89
|
+
jar,
|
|
90
|
+
clientID,
|
|
91
|
+
appID: primaryAppID,
|
|
92
|
+
mqttAppID: mqttAppID,
|
|
93
|
+
userAppID: userAppID,
|
|
94
|
+
globalOptions,
|
|
95
|
+
loggedIn: true,
|
|
96
|
+
access_token: "NONE",
|
|
97
|
+
clientMutationId: 0,
|
|
98
|
+
mqttClient: undefined,
|
|
99
|
+
lastSeqId: irisSeqID,
|
|
100
|
+
syncToken: undefined,
|
|
101
|
+
mqttEndpoint,
|
|
102
|
+
wsReqNumber: 0,
|
|
103
|
+
wsTaskNumber: 0,
|
|
104
|
+
reqCallbacks: {},
|
|
105
|
+
callback_Task: {},
|
|
106
|
+
region,
|
|
107
|
+
firstListen: true,
|
|
108
|
+
cache: new SimpleCache(),
|
|
109
|
+
validator: globalValidator,
|
|
110
|
+
_emitter: emitter,
|
|
111
|
+
...dtsgResult,
|
|
112
|
+
};
|
|
113
|
+
const defaultFuncs = utils.makeDefaults(html, userID, ctx);
|
|
114
|
+
|
|
115
|
+
return [ctx, defaultFuncs, {}];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
module.exports = buildAPI;
|