@cexy/hoonfca 1.0.1 → 1.0.2

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.
Files changed (170) hide show
  1. package/.travis.yml +6 -0
  2. package/LICENSE-MIT +21 -0
  3. package/index.d.ts +620 -0
  4. package/index.js +778 -1
  5. package/package.json +31 -84
  6. package/src/{apis/addExternalModule.js → addExternalModule.js} +4 -5
  7. package/src/addUserToGroup.js +113 -0
  8. package/src/changeAdminStatus.js +95 -0
  9. package/src/changeApprovalMode.js +79 -0
  10. package/src/changeArchivedStatus.js +55 -0
  11. package/src/changeBio.js +76 -0
  12. package/src/changeBlockedStatus.js +47 -0
  13. package/src/changeBlockedStatusMqtt.js +86 -0
  14. package/src/changeGroupImage.js +133 -0
  15. package/src/changeNickname.js +59 -0
  16. package/src/changeThreadColor.js +71 -0
  17. package/src/{apis/changeThreadEmoji.js → changeThreadEmoji.js} +8 -6
  18. package/src/createNewGroup.js +88 -0
  19. package/src/createPoll.js +130 -0
  20. package/src/deleteMessage.js +56 -0
  21. package/src/deleteThread.js +56 -0
  22. package/src/editMessage.js +63 -0
  23. package/src/forwardAttachment.js +60 -0
  24. package/src/forwardMessage.js +63 -0
  25. package/src/getCurrentUserID.js +7 -0
  26. package/src/getEmojiUrl.js +29 -0
  27. package/src/getFriendsList.js +84 -0
  28. package/src/getGroupsList.js +83 -0
  29. package/src/getMarketplace.js +84 -0
  30. package/src/getNotifications.js +86 -0
  31. package/src/getPagesList.js +83 -0
  32. package/src/getStories.js +88 -0
  33. package/src/getThreadHistory.js +647 -0
  34. package/src/getThreadInfo.js +222 -0
  35. package/src/getThreadList.js +292 -0
  36. package/src/getThreadPictures.js +79 -0
  37. package/src/getUserID.js +66 -0
  38. package/src/getUserInfo.js +128 -0
  39. package/src/handleFriendRequest.js +57 -0
  40. package/src/handleMessageRequest.js +65 -0
  41. package/src/{apis/httpGet.js → httpGet.js} +15 -20
  42. package/src/httpPost.js +58 -0
  43. package/src/listenMqtt.js +1018 -0
  44. package/src/logout.js +75 -0
  45. package/src/markAsDelivered.js +58 -0
  46. package/src/{apis/markAsRead.js → markAsRead.js} +19 -30
  47. package/src/markAsReadAll.js +50 -0
  48. package/src/markAsSeen.js +61 -0
  49. package/src/muteThread.js +52 -0
  50. package/src/pinMessage.js +61 -0
  51. package/src/removeUserFromGroup.js +79 -0
  52. package/src/resolvePhotoUrl.js +45 -0
  53. package/src/searchForThread.js +53 -0
  54. package/src/searchUsers.js +89 -0
  55. package/src/sendComment.js +161 -0
  56. package/src/sendMessage.js +457 -0
  57. package/src/sendTypingIndicator.js +179 -0
  58. package/src/setBio.js +86 -0
  59. package/src/setMessageReaction.js +186 -0
  60. package/src/setPostReaction.js +71 -0
  61. package/src/setTheme.js +313 -0
  62. package/src/setTitle.js +90 -0
  63. package/src/shareContact.js +53 -0
  64. package/src/shareLink.js +62 -0
  65. package/src/threadColors.js +57 -0
  66. package/src/unfriend.js +53 -0
  67. package/src/unsendMessage.js +104 -0
  68. package/utils.js +1447 -0
  69. package/LICENSE +0 -3
  70. package/README.md +0 -491
  71. package/examples/login-with-cookies.js +0 -102
  72. package/examples/verify.js +0 -70
  73. package/src/apis/addUserToGroup.js +0 -108
  74. package/src/apis/changeAdminStatus.js +0 -148
  75. package/src/apis/changeArchivedStatus.js +0 -61
  76. package/src/apis/changeAvatar.js +0 -103
  77. package/src/apis/changeBio.js +0 -69
  78. package/src/apis/changeBlockedStatus.js +0 -54
  79. package/src/apis/changeGroupImage.js +0 -136
  80. package/src/apis/changeThreadColor.js +0 -116
  81. package/src/apis/comment.js +0 -207
  82. package/src/apis/createAITheme.js +0 -129
  83. package/src/apis/createNewGroup.js +0 -79
  84. package/src/apis/createPoll.js +0 -73
  85. package/src/apis/deleteMessage.js +0 -44
  86. package/src/apis/deleteThread.js +0 -52
  87. package/src/apis/e2ee.js +0 -17
  88. package/src/apis/editMessage.js +0 -70
  89. package/src/apis/emoji.js +0 -124
  90. package/src/apis/fetchThemeData.js +0 -82
  91. package/src/apis/follow.js +0 -81
  92. package/src/apis/forwardMessage.js +0 -52
  93. package/src/apis/friend.js +0 -243
  94. package/src/apis/gcmember.js +0 -122
  95. package/src/apis/gcname.js +0 -123
  96. package/src/apis/gcrule.js +0 -119
  97. package/src/apis/getAccess.js +0 -111
  98. package/src/apis/getBotInfo.js +0 -88
  99. package/src/apis/getBotInitialData.js +0 -43
  100. package/src/apis/getFriendsList.js +0 -79
  101. package/src/apis/getMessage.js +0 -423
  102. package/src/apis/getTheme.js +0 -95
  103. package/src/apis/getThemeInfo.js +0 -116
  104. package/src/apis/getThreadHistory.js +0 -239
  105. package/src/apis/getThreadInfo.js +0 -267
  106. package/src/apis/getThreadList.js +0 -232
  107. package/src/apis/getThreadPictures.js +0 -58
  108. package/src/apis/getUserID.js +0 -117
  109. package/src/apis/getUserInfo.js +0 -513
  110. package/src/apis/getUserInfoV2.js +0 -146
  111. package/src/apis/handleMessageRequest.js +0 -50
  112. package/src/apis/httpPost.js +0 -89
  113. package/src/apis/httpPostFormData.js +0 -69
  114. package/src/apis/listenMqtt.js +0 -1236
  115. package/src/apis/listenSpeed.js +0 -179
  116. package/src/apis/logout.js +0 -87
  117. package/src/apis/markAsDelivered.js +0 -47
  118. package/src/apis/markAsReadAll.js +0 -40
  119. package/src/apis/markAsSeen.js +0 -70
  120. package/src/apis/mqttDeltaValue.js +0 -278
  121. package/src/apis/muteThread.js +0 -45
  122. package/src/apis/nickname.js +0 -132
  123. package/src/apis/notes.js +0 -163
  124. package/src/apis/pinMessage.js +0 -150
  125. package/src/apis/produceMetaTheme.js +0 -180
  126. package/src/apis/realtime.js +0 -182
  127. package/src/apis/removeUserFromGroup.js +0 -117
  128. package/src/apis/resolvePhotoUrl.js +0 -58
  129. package/src/apis/searchForThread.js +0 -154
  130. package/src/apis/sendMessage.js +0 -354
  131. package/src/apis/sendMessageMqtt.js +0 -249
  132. package/src/apis/sendTypingIndicator.js +0 -91
  133. package/src/apis/setMessageReaction.js +0 -27
  134. package/src/apis/setMessageReactionMqtt.js +0 -61
  135. package/src/apis/setThreadTheme.js +0 -260
  136. package/src/apis/setThreadThemeMqtt.js +0 -94
  137. package/src/apis/share.js +0 -107
  138. package/src/apis/shareContact.js +0 -66
  139. package/src/apis/stickers.js +0 -257
  140. package/src/apis/story.js +0 -181
  141. package/src/apis/theme.js +0 -233
  142. package/src/apis/unfriend.js +0 -47
  143. package/src/apis/unsendMessage.js +0 -17
  144. package/src/engine/client.js +0 -92
  145. package/src/engine/models/buildAPI.js +0 -152
  146. package/src/engine/models/loginHelper.js +0 -519
  147. package/src/engine/models/setOptions.js +0 -88
  148. package/src/security/e2ee.js +0 -109
  149. package/src/types/index.d.ts +0 -498
  150. package/src/utils/antiSuspension.js +0 -506
  151. package/src/utils/auth-helpers.js +0 -149
  152. package/src/utils/autoReLogin.js +0 -336
  153. package/src/utils/axios.js +0 -436
  154. package/src/utils/cache.js +0 -54
  155. package/src/utils/clients.js +0 -282
  156. package/src/utils/constants.js +0 -410
  157. package/src/utils/formatters/data/formatAttachment.js +0 -370
  158. package/src/utils/formatters/data/formatDelta.js +0 -109
  159. package/src/utils/formatters/index.js +0 -159
  160. package/src/utils/formatters/value/formatCookie.js +0 -91
  161. package/src/utils/formatters/value/formatDate.js +0 -36
  162. package/src/utils/formatters/value/formatID.js +0 -16
  163. package/src/utils/formatters.js +0 -1373
  164. package/src/utils/headers.js +0 -230
  165. package/src/utils/index.js +0 -153
  166. package/src/utils/monitoring.js +0 -333
  167. package/src/utils/rateLimiter.js +0 -319
  168. package/src/utils/tokenRefresh.js +0 -657
  169. package/src/utils/user-agents.js +0 -238
  170. package/src/utils/validation.js +0 -157
@@ -1,179 +0,0 @@
1
- "use strict";
2
-
3
- const utils = require('../utils');
4
- const mqtt = require('mqtt');
5
- const websocket = require('websocket-stream');
6
- const HttpsProxyAgent = require('https-proxy-agent');
7
- const EventEmitter = require('events');
8
-
9
- function connectLightspeed(ctx, globalCallback) {
10
- let client;
11
- let isStopped = false;
12
- const guard = (label, fn) => (...args) => {
13
- try {
14
- return fn(...args);
15
- } catch (err) {
16
- utils.error(`[Lightspeed] ${label} handler error:`, err && err.message ? err.message : err);
17
- }
18
- };
19
-
20
- function startConnection(retryCount = 0) {
21
- if (isStopped) return;
22
-
23
- const chatOn = ctx.globalOptions.online;
24
- const foreground = false;
25
- const sessionID = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER) + 1;
26
- const cookies = ctx.jar.getCookiesSync('https://www.facebook.com').join('; ');
27
- const cid = ctx.clientID;
28
-
29
- const username = {
30
- u: ctx.userID,
31
- s: sessionID,
32
- chat_on: chatOn,
33
- fg: foreground,
34
- d: cid,
35
- ct: 'websocket',
36
- aid: '2220391788200892',
37
- mqtt_sid: '',
38
- cp: 3,
39
- ecp: 10,
40
- st: [],
41
- pm: [],
42
- dc: '',
43
- no_auto_fg: true,
44
- gas: null,
45
- pack: [],
46
- a: ctx.globalOptions.userAgent,
47
- };
48
-
49
- const queryParams = new URLSearchParams({
50
- 'x-dgw-appid': '2220391788200892',
51
- 'x-dgw-appversion': '0',
52
- 'x-dgw-authtype': '1:0',
53
- 'x-dgw-version': '5',
54
- 'x-dgw-uuid': ctx.userID,
55
- 'x-dgw-tier': 'prod',
56
- 'x-dgw-loggingid': utils.getGUID(),
57
- 'x-dgw-regionhint': ctx.region || 'PRN',
58
- 'x-dgw-deviceid': ctx.clientID
59
- });
60
- const host = `wss://gateway.facebook.com/ws/lightspeed?${queryParams.toString()}`;
61
-
62
- // Generate a unique clientId per session, just like a real browser would
63
- const lsClientId = 'mqttwsclient_' + Math.random().toString(36).slice(2, 10) + Date.now().toString(36);
64
- const options = {
65
- clientId: lsClientId,
66
- protocolId: 'MQIsdp',
67
- protocolVersion: 3,
68
- username: JSON.stringify(username),
69
- clean: true,
70
- wsOptions: {
71
- headers: {
72
- 'Cookie': cookies,
73
- 'Origin': 'https://www.facebook.com',
74
- 'User-Agent': username.a,
75
- 'Referer': 'https://www.facebook.com/',
76
- 'Host': new URL(host).hostname
77
- }
78
- },
79
- keepalive: 60, // 60s is standard; 10s was too aggressive (sent PING every 10 seconds)
80
- reconnectPeriod: 0
81
- };
82
-
83
- if (ctx.globalOptions.proxy) {
84
- options.wsOptions.agent = new HttpsProxyAgent(ctx.globalOptions.proxy);
85
- }
86
-
87
- try {
88
- client = new mqtt.Client(_ => websocket(host, options.wsOptions), options);
89
- utils.log("[Lightspeed] Attempting MQTT connection...");
90
- } catch (err) {
91
- utils.error("[Lightspeed] MQTT Client creation failed:", err.message);
92
- reconnect(retryCount + 1);
93
- return;
94
- }
95
-
96
- client.on('connect', guard("connect", () => {
97
- utils.log("[Lightspeed] MQTT client connected. Attempting to subscribe to topics...");
98
- retryCount = 0;
99
-
100
-
101
- const topicsToSubscribe = [
102
- "/t_ms", // Para sa mga messages at deltas
103
- "/orca_presence", // Para sa online status
104
- "/messaging_events" // Para sa ibang events
105
- ];
106
-
107
- topicsToSubscribe.forEach(topic => {
108
- client.subscribe(topic, (err) => {
109
- if (err) {
110
- utils.error(`[Lightspeed] Failed to subscribe to topic ${topic}:`, err.message);
111
- } else {
112
- utils.log(`[Lightspeed] Subscribed to topic: ${topic}`);
113
- }
114
- });
115
- });
116
-
117
- }));
118
-
119
- client.on('message', guard("message", (topic, payload) => {
120
- utils.log(`[Lightspeed] Payload Received on topic ${topic}:`);
121
- globalCallback(null, { type: 'lightspeed_message', topic: topic.toString(), payload: payload });
122
- }));
123
-
124
- client.on('close', guard("close", () => {
125
- utils.warn(`[Lightspeed] Connection closed.`);
126
- if (!isStopped) {
127
- reconnect(retryCount + 1);
128
- }
129
- }));
130
-
131
- client.on('error', guard("error", (err) => {
132
- utils.error("[Lightspeed] MQTT Connection Error:", err.message);
133
- }));
134
- }
135
-
136
- function reconnect(retryCount) {
137
- const delay = Math.min(3000 * Math.pow(2, retryCount), 60000);
138
- utils.log(`[Lightspeed] Reconnecting in ${delay / 1000} seconds...`);
139
- setTimeout(() => startConnection(retryCount), delay);
140
- }
141
-
142
- startConnection();
143
-
144
- return {
145
- stop: () => {
146
- isStopped = true;
147
- if (client) client.end(true);
148
- utils.log("[Lightspeed] Listener has been manually stopped.");
149
- }
150
- };
151
- }
152
-
153
- module.exports = function (defaultFuncs, api, ctx) {
154
- return (callback) => {
155
- class MessageEmitter extends EventEmitter {
156
- constructor() {
157
- super();
158
- this.listener = null;
159
- }
160
- stop() {
161
- if (this.listener) {
162
- this.listener.stop();
163
- }
164
- this.emit('stop');
165
- }
166
- }
167
- const msgEmitter = new MessageEmitter();
168
- const globalCallback = (error, message) => {
169
- if (error) return msgEmitter.emit("error", error);
170
- msgEmitter.emit("message", message);
171
- };
172
- if (typeof callback === 'function') {
173
- msgEmitter.listener = connectLightspeed(ctx, callback);
174
- } else {
175
- msgEmitter.listener = connectLightspeed(ctx, globalCallback);
176
- }
177
- return msgEmitter;
178
- };
179
- };
@@ -1,87 +0,0 @@
1
- "use strict";
2
-
3
- const utils = require('../utils');
4
-
5
- /**
6
- * @param {Object} defaultFuncs
7
- * @param {Object} api
8
- * @param {Object} ctx
9
- * @returns {function(): Promise<void>}
10
- */
11
- module.exports = function (defaultFuncs, api, ctx) {
12
- /**
13
- * Logs the current user out of Facebook.
14
- * @returns {Promise<void>} A promise that resolves when logout is successful or rejects on error.
15
- */
16
- return async function logout() {
17
- const form = {
18
- pmid: "0",
19
- };
20
-
21
- try {
22
- const resData = await defaultFuncs
23
- .post(
24
- "https://www.facebook.com/bluebar/modern_settings_menu/?help_type=364455653583099&show_contextual_help=1",
25
- ctx.jar,
26
- form,
27
- )
28
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs));
29
-
30
- const elem = resData.jsmods.instances[0][2][0].find(v => v.value === "logout");
31
- if (!elem) {
32
- throw { error: "Could not find logout form element." };
33
- }
34
-
35
- const html = resData.jsmods.markup.find(v => v[0] === elem.markup.__m)[1].__html;
36
-
37
- const logoutForm = {
38
- fb_dtsg: utils.getFrom(html, '"fb_dtsg" value="', '"'),
39
- ref: utils.getFrom(html, '"ref" value="', '"'),
40
- h: utils.getFrom(html, '"h" value="', '"'),
41
- };
42
-
43
- const logoutRes = await defaultFuncs
44
- .post("https://www.facebook.com/logout.php", ctx.jar, logoutForm)
45
- .then(utils.saveCookies(ctx.jar));
46
-
47
- if (!logoutRes.headers || !logoutRes.headers.location) {
48
- throw { error: "An error occurred when logging out." };
49
- }
50
-
51
- await defaultFuncs
52
- .get(logoutRes.headers.location, ctx.jar)
53
- .then(utils.saveCookies(ctx.jar));
54
-
55
- ctx.loggedIn = false;
56
-
57
- // Clear sensitive session tokens so stale credentials cannot be reused
58
- // if this ctx object is accidentally referenced again after logout.
59
- ctx.fb_dtsg = undefined;
60
- ctx.fb_dtsg_ag = undefined;
61
- ctx.lsd = undefined;
62
- ctx.access_token = undefined;
63
-
64
- // Stop background timers that are owned by this session, if present.
65
- if (typeof ctx._stopTokenRefresh === 'function') {
66
- try { ctx._stopTokenRefresh(); } catch (_) {}
67
- }
68
- if (typeof ctx._stopAutoReLogin === 'function') {
69
- try { ctx._stopAutoReLogin(); } catch (_) {}
70
- }
71
- if (typeof ctx._stopCookieBackup === 'function') {
72
- try { ctx._stopCookieBackup(); } catch (_) {}
73
- }
74
-
75
- // Invalidate the response cache so nothing stale is served after logout.
76
- if (ctx.cache && typeof ctx.cache.clear === 'function') {
77
- ctx.cache.clear();
78
- }
79
-
80
- utils.log("logout", "Logged out successfully.");
81
-
82
- } catch (err) {
83
- utils.error("logout", err);
84
- throw err;
85
- }
86
- };
87
- };
@@ -1,47 +0,0 @@
1
-
2
- "use strict";
3
-
4
- const utils = require('../utils');
5
- /**
6
- * @param {Object} defaultFuncs
7
- * @param {Object} api
8
- * @param {Object} ctx
9
- * @returns {function(threadID: string, messageID: string): Promise<void>}
10
- */
11
- module.exports = function (defaultFuncs, api, ctx) {
12
- /**
13
- * Marks a message as delivered.
14
- * @param {string} threadID - The ID of the thread.
15
- * @param {string} messageID - The ID of the message to mark as delivered.
16
- * @returns {Promise<void>} A promise that resolves on success or rejects on error.
17
- */
18
- return async function markAsDelivered(threadID, messageID) {
19
- if (!threadID || !messageID) {
20
- const err = "Error: messageID or threadID is not defined";
21
- utils.error("markAsDelivered", err);
22
- throw new Error(err);
23
- }
24
-
25
- const form = {};
26
- form["message_ids[0]"] = messageID;
27
- form["thread_ids[" + threadID + "][0]"] = messageID;
28
-
29
- try {
30
- const resData = await defaultFuncs
31
- .post(
32
- "https://www.facebook.com/ajax/mercury/delivery_receipts.php",
33
- ctx.jar,
34
- form,
35
- )
36
- .then(utils.saveCookies(ctx.jar))
37
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs));
38
-
39
- if (resData.error) {
40
- throw resData;
41
- }
42
- } catch (err) {
43
- utils.error("markAsDelivered", err);
44
- throw err;
45
- }
46
- };
47
- };
@@ -1,40 +0,0 @@
1
- "use strict";
2
-
3
- const utils = require('../utils');
4
-
5
-
6
- /**
7
- * @param {Object} defaultFuncs
8
- * @param {Object} api
9
- * @param {Object} ctx
10
- * @returns {function(): Promise<void>}
11
- */
12
- module.exports = function (defaultFuncs, api, ctx) {
13
- /**
14
- * @returns {Promise<void>}
15
- */
16
- return async function markAsReadAll() {
17
- const form = {
18
- folder: "inbox",
19
- };
20
-
21
- try {
22
- const parsedData = await defaultFuncs
23
- .post(
24
- "https://www.facebook.com/ajax/mercury/mark_folder_as_read.php",
25
- ctx.jar,
26
- form
27
- )
28
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs));
29
-
30
- if (parsedData.error) {
31
- throw parsedData;
32
- }
33
-
34
- return;
35
- } catch (err) {
36
- utils.error("markAsReadAll", err);
37
- throw err;
38
- }
39
- };
40
- };
@@ -1,70 +0,0 @@
1
- "use strict";
2
-
3
- const utils = require('../utils');
4
-
5
- /**
6
- * @param {Object} defaultFuncs
7
- * @param {Object} api
8
- * @param {Object} ctx
9
- */
10
- module.exports = function (defaultFuncs, api, ctx) {
11
- /**
12
- * Marks all messages as "seen" up to a specific timestamp.
13
- * @param {number} [seen_timestamp=Date.now()] - The timestamp (in milliseconds) up to which messages should be marked as seen. If a function is provided, it's treated as the callback and the timestamp defaults to the current time.
14
- * @param {Function} [callback] - The callback function.
15
- * @returns {Promise<void>} A Promise that resolves on success or rejects with an error.
16
- */
17
- return async function markAsSeen(seen_timestamp, callback) {
18
- let resolveFunc = function () {};
19
- let rejectFunc = function () {};
20
- const returnPromise = new Promise(function (resolve, reject) {
21
- resolveFunc = resolve;
22
- rejectFunc = reject;
23
- });
24
-
25
- if (utils.getType(seen_timestamp) == "Function" || utils.getType(seen_timestamp) == "AsyncFunction") {
26
- callback = seen_timestamp;
27
- seen_timestamp = Date.now();
28
- } else if (seen_timestamp === undefined) {
29
- seen_timestamp = Date.now();
30
- }
31
-
32
- if (!callback) {
33
- callback = function (err, friendList) {
34
- if (err) {
35
- return rejectFunc(err);
36
- }
37
- resolveFunc(friendList);
38
- };
39
- }
40
-
41
- const form = {
42
- seen_timestamp: seen_timestamp,
43
- };
44
-
45
- try {
46
- const resData = await defaultFuncs
47
- .post(
48
- "https://www.facebook.com/ajax/mercury/mark_seen.php",
49
- ctx.jar,
50
- form,
51
- )
52
- .then(utils.saveCookies(ctx.jar))
53
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs));
54
-
55
- if (resData.error) {
56
- throw resData;
57
- }
58
-
59
- return callback();
60
- } catch (err) {
61
- utils.error("markAsSeen", err);
62
- if (utils.getType(err) == "Object" && err.error === "Not logged in.") {
63
- ctx.loggedIn = false;
64
- }
65
- return callback(err);
66
- }
67
-
68
- return returnPromise;
69
- };
70
- };