nayan-remake-api 0.0.1-security → 3.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.

Potentially problematic release.


This version of nayan-remake-api might be problematic. Click here for more details.

Files changed (71) hide show
  1. package/.cache/replit/__replit_disk_meta.json +1 -0
  2. package/.config/configstore/update-notifier-npm.json +4 -0
  3. package/.config/configstore/update-notifier-npm.json.1735545094 +4 -0
  4. package/.github/workflows/nodejs.yml +26 -0
  5. package/.replit +80 -0
  6. package/CHANGELOG.md +2 -0
  7. package/DOCS.md +1947 -0
  8. package/LICENSE-MIT +21 -0
  9. package/README.md +198 -3
  10. package/index.js +641 -0
  11. package/package.json +69 -3
  12. package/replit.nix +8 -0
  13. package/src/addExternalModule.js +19 -0
  14. package/src/addUserToGroup.js +113 -0
  15. package/src/changeAdminStatus.js +79 -0
  16. package/src/changeArchivedStatus.js +55 -0
  17. package/src/changeAvatar.js +127 -0
  18. package/src/changeBio.js +77 -0
  19. package/src/changeBlockedStatus.js +47 -0
  20. package/src/changeGroupImage.js +133 -0
  21. package/src/changeNickname.js +59 -0
  22. package/src/changeThreadColor.js +65 -0
  23. package/src/changeThreadEmoji.js +55 -0
  24. package/src/createNewGroup.js +86 -0
  25. package/src/createPoll.js +71 -0
  26. package/src/deleteMessage.js +56 -0
  27. package/src/deleteThread.js +56 -0
  28. package/src/forwardAttachment.js +60 -0
  29. package/src/getCurrentUserID.js +7 -0
  30. package/src/getEmojiUrl.js +29 -0
  31. package/src/getFriendsList.js +84 -0
  32. package/src/getMessage.js +716 -0
  33. package/src/getThreadHistory.js +666 -0
  34. package/src/getThreadInfo.js +232 -0
  35. package/src/getThreadList.js +237 -0
  36. package/src/getThreadPictures.js +79 -0
  37. package/src/getUserID.js +66 -0
  38. package/src/getUserInfo.js +74 -0
  39. package/src/handleFriendRequest.js +61 -0
  40. package/src/handleMessageRequest.js +65 -0
  41. package/src/httpGet.js +57 -0
  42. package/src/httpPost.js +57 -0
  43. package/src/httpPostFormData.js +59 -0
  44. package/src/listenMqtt.js +862 -0
  45. package/src/logout.js +75 -0
  46. package/src/markAsDelivered.js +58 -0
  47. package/src/markAsRead.js +80 -0
  48. package/src/markAsReadAll.js +50 -0
  49. package/src/markAsSeen.js +59 -0
  50. package/src/muteThread.js +52 -0
  51. package/src/n +1 -0
  52. package/src/removeUserFromGroup.js +79 -0
  53. package/src/resolvePhotoUrl.js +45 -0
  54. package/src/searchForThread.js +53 -0
  55. package/src/sendMessage.js +449 -0
  56. package/src/sendTypingIndicator.js +103 -0
  57. package/src/setMessageReaction.js +117 -0
  58. package/src/setPostReaction.js +109 -0
  59. package/src/setTitle.js +86 -0
  60. package/src/threadColors.js +120 -0
  61. package/src/unfriend.js +52 -0
  62. package/src/unsendMessage.js +49 -0
  63. package/src/uploadAttachment.js +96 -0
  64. package/test/data/N +1 -0
  65. package/test/data/shareAttach.js +146 -0
  66. package/test/data/test.txt +7 -0
  67. package/test/example-config.json +18 -0
  68. package/test/n +1 -0
  69. package/test/test-page.js +140 -0
  70. package/test/test.js +387 -0
  71. package/utils.js +1451 -0
package/package.json CHANGED
@@ -1,6 +1,72 @@
1
1
  {
2
2
  "name": "nayan-remake-api",
3
- "version": "0.0.1-security",
4
- "description": "security holding package",
5
- "repository": "npm/security-holder"
3
+ "version": "3.0.2",
4
+ "description": "A Facebook chat API that doesn't rely on XMPP",
5
+ "scripts": {
6
+ "test": "mocha",
7
+ "lint": "./node_modules/.bin/eslint **.js",
8
+ "prettier": "prettier utils.js src/* --write"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/NAYAN-BOT69/nayan-remake-api.git"
13
+ },
14
+ "keywords": [
15
+ "facebook",
16
+ "chat",
17
+ "api",
18
+ "fca",
19
+ "nayan-remake-api"
20
+ ],
21
+ "bugs": {
22
+ "url": "https://github.com/NAYAN-BOT69/nayan-remake-api/issues"
23
+ },
24
+ "author": "Avery, David, Maude, Benjamin, UIRI, Nayan (rebuild)",
25
+ "license": "MIT",
26
+ "dependencies": {
27
+ "bluebird": "^2.11.0",
28
+ "cheerio": "^0.22.0",
29
+ "https-proxy-agent": "^4.0.0",
30
+ "mqtt": "^3.0.0",
31
+ "npmlog": "^1.2.0",
32
+ "request": "^2.53.0",
33
+ "websocket-stream": "^5.5.0"
34
+ },
35
+ "engines": {
36
+ "node": ">=10.x"
37
+ },
38
+ "devDependencies": {
39
+ "eslint": "^7.5.0",
40
+ "mocha": "^7.0.1",
41
+ "prettier": "^1.11.1"
42
+ },
43
+ "eslintConfig": {
44
+ "env": {
45
+ "commonjs": true,
46
+ "es2021": true,
47
+ "node": true
48
+ },
49
+ "extends": "eslint:recommended",
50
+ "parserOptions": {
51
+ "ecmaVersion": 13
52
+ },
53
+ "rules": {
54
+ "no-prototype-builtins": 0,
55
+ "no-unused-vars": 1,
56
+ "comma-dangle": 1,
57
+ "no-redeclare": 0,
58
+ "prefer-const": 1,
59
+ "no-useless-escape": 0,
60
+ "no-mixed-spaces-and-tabs": 0,
61
+ "semi": 1,
62
+ "no-useless-catch": 0,
63
+ "no-empty": 0,
64
+ "use-isnan": 0,
65
+ "no-extra-semi": 1,
66
+ "no-async-promise-executor": 0,
67
+ "no-unreachable": 1,
68
+ "valid-typeof": 0,
69
+ "no-case-declarations": 0
70
+ }
71
+ }
6
72
  }
package/replit.nix ADDED
@@ -0,0 +1,8 @@
1
+ { pkgs }: {
2
+ deps = [
3
+ pkgs.nodejs-18_x
4
+ pkgs.nodePackages.typescript-language-server
5
+ pkgs.yarn
6
+ pkgs.replitPackages.jest
7
+ ];
8
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+
5
+ module.exports = function (defaultFuncs, api, ctx) {
6
+ return function addExternalModule(moduleObj) {
7
+ if (utils.getType(moduleObj) == "Object") {
8
+ for (const apiName in moduleObj) {
9
+ if (utils.getType(moduleObj[apiName]) == "Function") {
10
+ api[apiName] = moduleObj[apiName](defaultFuncs, api, ctx);
11
+ } else {
12
+ throw new Error(`Item "${apiName}" in moduleObj must be a function, not ${utils.getType(moduleObj[apiName])}!`);
13
+ }
14
+ }
15
+ } else {
16
+ throw new Error(`moduleObj must be an object, not ${utils.getType(moduleObj)}!`);
17
+ }
18
+ };
19
+ };
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function addUserToGroup(userID, threadID, callback) {
8
+ let resolveFunc = function () { };
9
+ let rejectFunc = function () { };
10
+ const returnPromise = new Promise(function (resolve, reject) {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+
15
+ if (
16
+ !callback &&
17
+ (utils.getType(threadID) === "Function" ||
18
+ utils.getType(threadID) === "AsyncFunction")
19
+ ) {
20
+ throw { error: "please pass a threadID as a second argument." };
21
+ }
22
+
23
+ if (!callback) {
24
+ callback = function (err) {
25
+ if (err) {
26
+ return rejectFunc(err);
27
+ }
28
+ resolveFunc();
29
+ };
30
+ }
31
+
32
+ if (
33
+ utils.getType(threadID) !== "Number" &&
34
+ utils.getType(threadID) !== "String"
35
+ ) {
36
+ throw {
37
+ error:
38
+ "ThreadID should be of type Number or String and not " +
39
+ utils.getType(threadID) +
40
+ "."
41
+ };
42
+ }
43
+
44
+ if (utils.getType(userID) !== "Array") {
45
+ userID = [userID];
46
+ }
47
+
48
+ const messageAndOTID = utils.generateOfflineThreadingID();
49
+ const form = {
50
+ client: "mercury",
51
+ action_type: "ma-type:log-message",
52
+ author: "fbid:" + ctx.userID,
53
+ thread_id: "",
54
+ timestamp: Date.now(),
55
+ timestamp_absolute: "Today",
56
+ timestamp_relative: utils.generateTimestampRelative(),
57
+ timestamp_time_passed: "0",
58
+ is_unread: false,
59
+ is_cleared: false,
60
+ is_forward: false,
61
+ is_filtered_content: false,
62
+ is_filtered_content_bh: false,
63
+ is_filtered_content_account: false,
64
+ is_spoof_warning: false,
65
+ source: "source:chat:web",
66
+ "source_tags[0]": "source:chat",
67
+ log_message_type: "log:subscribe",
68
+ status: "0",
69
+ offline_threading_id: messageAndOTID,
70
+ message_id: messageAndOTID,
71
+ threading_id: utils.generateThreadingID(ctx.clientID),
72
+ manual_retry_cnt: "0",
73
+ thread_fbid: threadID
74
+ };
75
+
76
+ for (let i = 0; i < userID.length; i++) {
77
+ if (
78
+ utils.getType(userID[i]) !== "Number" &&
79
+ utils.getType(userID[i]) !== "String"
80
+ ) {
81
+ throw {
82
+ error:
83
+ "Elements of userID should be of type Number or String and not " +
84
+ utils.getType(userID[i]) +
85
+ "."
86
+ };
87
+ }
88
+
89
+ form["log_message_data[added_participants][" + i + "]"] =
90
+ "fbid:" + userID[i];
91
+ }
92
+
93
+ defaultFuncs
94
+ .post("https://www.facebook.com/messaging/send/", ctx.jar, form)
95
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
96
+ .then(function (resData) {
97
+ if (!resData) {
98
+ throw { error: "Add to group failed." };
99
+ }
100
+ if (resData.error) {
101
+ throw resData;
102
+ }
103
+
104
+ return callback();
105
+ })
106
+ .catch(function (err) {
107
+ log.error("addUserToGroup", err);
108
+ return callback(err);
109
+ });
110
+
111
+ return returnPromise;
112
+ };
113
+ };
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function changeAdminStatus(threadID, adminIDs, adminStatus, callback) {
8
+ if (utils.getType(threadID) !== "String") {
9
+ throw { error: "changeAdminStatus: threadID must be a string" };
10
+ }
11
+
12
+ if (utils.getType(adminIDs) === "String") {
13
+ adminIDs = [adminIDs];
14
+ }
15
+
16
+ if (utils.getType(adminIDs) !== "Array") {
17
+ throw { error: "changeAdminStatus: adminIDs must be an array or string" };
18
+ }
19
+
20
+ if (utils.getType(adminStatus) !== "Boolean") {
21
+ throw { error: "changeAdminStatus: adminStatus must be a string" };
22
+ }
23
+
24
+ let resolveFunc = function () { };
25
+ let rejectFunc = function () { };
26
+ const returnPromise = new Promise(function (resolve, reject) {
27
+ resolveFunc = resolve;
28
+ rejectFunc = reject;
29
+ });
30
+
31
+ if (!callback) {
32
+ callback = function (err) {
33
+ if (err) {
34
+ return rejectFunc(err);
35
+ }
36
+ resolveFunc();
37
+ };
38
+ }
39
+
40
+ if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
41
+ throw { error: "changeAdminStatus: callback is not a function" };
42
+ }
43
+
44
+ const form = {
45
+ "thread_fbid": threadID
46
+ };
47
+
48
+ let i = 0;
49
+ for (const u of adminIDs) {
50
+ form[`admin_ids[${i++}]`] = u;
51
+ }
52
+ form["add"] = adminStatus;
53
+
54
+ defaultFuncs
55
+ .post("https://www.facebook.com/messaging/save_admins/?dpr=1", ctx.jar, form)
56
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
57
+ .then(function (resData) {
58
+ if (resData.error) {
59
+ switch (resData.error) {
60
+ case 1976004:
61
+ throw { error: "Cannot alter admin status: you are not an admin.", rawResponse: resData };
62
+ case 1357031:
63
+ throw { error: "Cannot alter admin status: this thread is not a group chat.", rawResponse: resData };
64
+ default:
65
+ throw { error: "Cannot alter admin status: unknown error.", rawResponse: resData };
66
+ }
67
+ }
68
+
69
+ callback();
70
+ })
71
+ .catch(function (err) {
72
+ log.error("changeAdminStatus", err);
73
+ return callback(err);
74
+ });
75
+
76
+ return returnPromise;
77
+ };
78
+ };
79
+
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function changeArchivedStatus(threadOrThreads, archive, callback) {
8
+ let resolveFunc = function () { };
9
+ let rejectFunc = function () { };
10
+ const returnPromise = new Promise(function (resolve, reject) {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+
15
+ if (!callback) {
16
+ callback = function (err) {
17
+ if (err) {
18
+ return rejectFunc(err);
19
+ }
20
+ resolveFunc();
21
+ };
22
+ }
23
+
24
+ const form = {};
25
+
26
+ if (utils.getType(threadOrThreads) === "Array") {
27
+ for (let i = 0; i < threadOrThreads.length; i++) {
28
+ form["ids[" + threadOrThreads[i] + "]"] = archive;
29
+ }
30
+ } else {
31
+ form["ids[" + threadOrThreads + "]"] = archive;
32
+ }
33
+
34
+ defaultFuncs
35
+ .post(
36
+ "https://www.facebook.com/ajax/mercury/change_archived_status.php",
37
+ ctx.jar,
38
+ form
39
+ )
40
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
41
+ .then(function (resData) {
42
+ if (resData.error) {
43
+ throw resData;
44
+ }
45
+
46
+ return callback();
47
+ })
48
+ .catch(function (err) {
49
+ log.error("changeArchivedStatus", err);
50
+ return callback(err);
51
+ });
52
+
53
+ return returnPromise;
54
+ };
55
+ };
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
+ const bluebird = require("bluebird");
6
+
7
+ module.exports = function (defaultFuncs, api, ctx) {
8
+ function handleUpload(image, callback) {
9
+ const uploads = [];
10
+
11
+ const form = {
12
+ profile_id: ctx.i_userID || ctx.userID,
13
+ photo_source: 57,
14
+ av: ctx.i_userID || ctx.userID,
15
+ file: image
16
+ };
17
+
18
+ uploads.push(
19
+ defaultFuncs
20
+ .postFormData(
21
+ "https://www.facebook.com/profile/picture/upload/",
22
+ ctx.jar,
23
+ form,
24
+ {}
25
+ )
26
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
27
+ .then(function (resData) {
28
+ if (resData.error) {
29
+ throw resData;
30
+ }
31
+ return resData;
32
+ })
33
+ );
34
+
35
+ // resolve all promises
36
+ bluebird
37
+ .all(uploads)
38
+ .then(function (resData) {
39
+ callback(null, resData);
40
+ })
41
+ .catch(function (err) {
42
+ log.error("handleUpload", err);
43
+ return callback(err);
44
+ });
45
+ }
46
+
47
+ return function changeAvatar(image, caption = "", timestamp = null, callback) {
48
+ let resolveFunc = function () { };
49
+ let rejectFunc = function () { };
50
+ const returnPromise = new Promise(function (resolve, reject) {
51
+ resolveFunc = resolve;
52
+ rejectFunc = reject;
53
+ });
54
+
55
+ if (!timestamp && utils.getType(caption) === "Number") {
56
+ timestamp = caption;
57
+ caption = "";
58
+ }
59
+
60
+ if (!timestamp && !callback && (utils.getType(caption) == "Function" || utils.getType(caption) == "AsyncFunction")) {
61
+ callback = caption;
62
+ caption = "";
63
+ timestamp = null;
64
+ }
65
+
66
+ if (!callback) callback = function (err, data) {
67
+ if (err) {
68
+ return rejectFunc(err);
69
+ }
70
+ resolveFunc(data);
71
+ };
72
+
73
+ if (!utils.isReadableStream(image))
74
+ return callback("Image is not a readable stream");
75
+
76
+ handleUpload(image, function (err, payload) {
77
+ if (err) {
78
+ return callback(err);
79
+ }
80
+
81
+ const form = {
82
+ av: ctx.i_userID || ctx.userID,
83
+ fb_api_req_friendly_name: "ProfileCometProfilePictureSetMutation",
84
+ fb_api_caller_class: "RelayModern",
85
+ doc_id: "5066134240065849",
86
+ variables: JSON.stringify({
87
+ input: {
88
+ caption,
89
+ existing_photo_id: payload[0].payload.fbid,
90
+ expiration_time: timestamp,
91
+ profile_id: ctx.i_userID || ctx.userID,
92
+ profile_pic_method: "EXISTING",
93
+ profile_pic_source: "TIMELINE",
94
+ scaled_crop_rect: {
95
+ height: 1,
96
+ width: 1,
97
+ x: 0,
98
+ y: 0
99
+ },
100
+ skip_cropping: true,
101
+ actor_id: ctx.i_userID || ctx.userID,
102
+ client_mutation_id: Math.round(Math.random() * 19).toString()
103
+ },
104
+ isPage: false,
105
+ isProfile: true,
106
+ scale: 3
107
+ })
108
+ };
109
+
110
+ defaultFuncs
111
+ .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
112
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
113
+ .then(function (resData) {
114
+ if (resData.errors) {
115
+ throw resData;
116
+ }
117
+ return callback(null, resData[0].data.profile_picture_set);
118
+ })
119
+ .catch(function (err) {
120
+ log.error("changeAvatar", err);
121
+ return callback(err);
122
+ });
123
+ });
124
+
125
+ return returnPromise;
126
+ };
127
+ };
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function changeBio(bio, publish, callback) {
8
+ let resolveFunc = function () { };
9
+ let rejectFunc = function () { };
10
+ const returnPromise = new Promise(function (resolve, reject) {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+
15
+ if (!callback) {
16
+ if (utils.getType(publish) == "Function" || utils.getType(publish) == "AsyncFunction") {
17
+ callback = publish;
18
+ } else {
19
+ callback = function (err) {
20
+ if (err) {
21
+ return rejectFunc(err);
22
+ }
23
+ resolveFunc();
24
+ };
25
+ }
26
+ }
27
+
28
+ if (utils.getType(publish) != "Boolean") {
29
+ publish = false;
30
+ }
31
+
32
+ if (utils.getType(bio) != "String") {
33
+ bio = "";
34
+ publish = false;
35
+ }
36
+
37
+ const form = {
38
+ fb_api_caller_class: "RelayModern",
39
+ fb_api_req_friendly_name: "ProfileCometSetBioMutation",
40
+ // This doc_is is valid as of May 23, 2020
41
+ doc_id: "2725043627607610",
42
+ variables: JSON.stringify({
43
+ input: {
44
+ bio: bio,
45
+ publish_bio_feed_story: publish,
46
+ actor_id: ctx.i_userID || ctx.userID,
47
+ client_mutation_id: Math.round(Math.random() * 1024).toString()
48
+ },
49
+ hasProfileTileViewID: false,
50
+ profileTileViewID: null,
51
+ scale: 1
52
+ }),
53
+ av: ctx.i_userID || ctx.userID
54
+ };
55
+
56
+ defaultFuncs
57
+ .post(
58
+ "https://www.facebook.com/api/graphql/",
59
+ ctx.jar,
60
+ form
61
+ )
62
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
63
+ .then(function (resData) {
64
+ if (resData.errors) {
65
+ throw resData;
66
+ }
67
+
68
+ return callback();
69
+ })
70
+ .catch(function (err) {
71
+ log.error("changeBio", err);
72
+ return callback(err);
73
+ });
74
+
75
+ return returnPromise;
76
+ };
77
+ };
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function changeBlockedStatus(userID, block, callback) {
8
+ let resolveFunc = function () { };
9
+ let rejectFunc = function () { };
10
+ const returnPromise = new Promise(function (resolve, reject) {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+
15
+ if (!callback) {
16
+ callback = function (err) {
17
+ if (err) {
18
+ return rejectFunc(err);
19
+ }
20
+ resolveFunc();
21
+ };
22
+ }
23
+
24
+ defaultFuncs
25
+ .post(
26
+ `https://www.facebook.com/messaging/${block ? "" : "un"}block_messages/`,
27
+ ctx.jar,
28
+ {
29
+ fbid: userID
30
+ }
31
+ )
32
+ .then(utils.saveCookies(ctx.jar))
33
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
34
+ .then(function (resData) {
35
+ if (resData.error) {
36
+ throw resData;
37
+ }
38
+
39
+ return callback();
40
+ })
41
+ .catch(function (err) {
42
+ log.error("changeBlockedStatus", err);
43
+ return callback(err);
44
+ });
45
+ return returnPromise;
46
+ };
47
+ };