fca-smart-shankar 10.9.1 → 13.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.
Files changed (169) hide show
  1. package/.replit +12 -3
  2. package/.upm/store.json +1 -1
  3. package/CHANGELOG.md +2 -0
  4. package/LICENSE-MIT +21 -0
  5. package/README.md +175 -30
  6. package/generated-icon.png +0 -0
  7. package/index.js +511 -414
  8. package/package.json +370 -85
  9. package/replit.nix +5 -0
  10. package/shankar-fca.json +4 -0
  11. package/src/addExternalModule.js +14 -5
  12. package/src/addUserToGroup.js +56 -20
  13. package/src/changeAdminStatus.js +44 -20
  14. package/src/changeArchivedStatus.js +25 -11
  15. package/src/changeAvatar.js +136 -0
  16. package/src/{changeAvt.js → changeAvatarV2.js} +3 -2
  17. package/src/changeBio.js +26 -15
  18. package/src/changeBlockedStatus.js +21 -8
  19. package/src/changeBlockedStatusMqtt.js +80 -0
  20. package/src/changeCover.js +73 -0
  21. package/src/changeGroupImage.js +53 -24
  22. package/src/changeName.js +79 -0
  23. package/src/changeNickname.js +27 -13
  24. package/src/changeThreadColor.js +22 -19
  25. package/src/changeThreadEmoji.js +24 -11
  26. package/src/changeUsername.js +59 -0
  27. package/src/createCommentPost.js +230 -0
  28. package/src/createNewGroup.js +38 -20
  29. package/src/createPoll.js +27 -16
  30. package/src/createPost.js +277 -0
  31. package/src/data/getThreadInfo.json +1 -0
  32. package/src/deleteMessage.js +24 -13
  33. package/src/deleteThread.js +25 -12
  34. package/src/editMessage.js +71 -53
  35. package/src/editMessageOld.js +67 -0
  36. package/src/follow.js +74 -0
  37. package/src/forwardAttachment.js +27 -15
  38. package/src/getAccess.js +112 -0
  39. package/src/getAvatarUser.js +78 -0
  40. package/src/getCurrentUserID.js +1 -1
  41. package/src/getEmojiUrl.js +10 -8
  42. package/src/getFriendsList.js +25 -15
  43. package/src/getMessage.js +813 -81
  44. package/src/getRegion.js +7 -0
  45. package/src/getThreadHistory.js +241 -98
  46. package/src/getThreadHistoryDeprecated.js +93 -0
  47. package/src/getThreadInfo.js +90 -287
  48. package/src/getThreadInfoDeprecated.js +80 -0
  49. package/src/getThreadList.js +214 -157
  50. package/src/getThreadListDeprecated.js +75 -0
  51. package/src/getThreadPictures.js +39 -19
  52. package/src/getUID.js +113 -50
  53. package/src/getUserID.js +18 -14
  54. package/src/getUserInfo.js +65 -71
  55. package/src/handleFriendRequest.js +24 -13
  56. package/src/handleMessageRequest.js +36 -20
  57. package/src/httpGet.js +34 -18
  58. package/src/httpPost.js +35 -18
  59. package/src/httpPostFormData.js +53 -24
  60. package/src/listenMqtt.js +680 -944
  61. package/src/listenNotification.js +85 -0
  62. package/src/logout.js +22 -15
  63. package/src/markAsDelivered.js +25 -15
  64. package/src/markAsRead.js +45 -27
  65. package/src/markAsReadAll.js +21 -14
  66. package/src/markAsSeen.js +28 -18
  67. package/src/muteThread.js +17 -12
  68. package/src/pinMessage.js +59 -0
  69. package/src/refreshFb_dtsg.js +89 -0
  70. package/src/removeUserFromGroup.js +47 -17
  71. package/src/resolvePhotoUrl.js +21 -13
  72. package/src/searchForThread.js +23 -13
  73. package/src/searchStickers.js +53 -0
  74. package/src/sendMessage.js +178 -117
  75. package/src/sendMessageMqtt.js +322 -0
  76. package/src/sendTypingIndicator.js +46 -16
  77. package/src/sendTypingIndicatorV2.js +28 -0
  78. package/src/setMessageReaction.js +33 -20
  79. package/src/setMessageReactionMqtt.js +62 -0
  80. package/src/setPostReaction.js +105 -95
  81. package/src/setProfileGuard.js +45 -0
  82. package/src/setStoryReaction.js +64 -0
  83. package/src/setTitle.js +34 -18
  84. package/src/shareContact.js +92 -37
  85. package/src/shareLink.js +5 -4
  86. package/src/stopListenMqtt.js +26 -0
  87. package/src/threadColors.js +110 -18
  88. package/src/unfriend.js +18 -9
  89. package/src/unsendMessage.js +31 -34
  90. package/src/uploadAttachment.js +94 -0
  91. package/test/data/shareAttach.js +1 -1
  92. package/test/test.js +1 -1
  93. package/utils.js +1393 -2918
  94. package/.cache/replit/env/latest +0 -56
  95. package/.cache/replit/env/latest.json +0 -1
  96. package/.cache/replit/modules/nodejs-14.res +0 -1
  97. package/.cache/replit/modules/replit.res +0 -1
  98. package/.cache/replit/modules/web.res +0 -1
  99. package/.cache/replit/modules.stamp +0 -0
  100. package/.cache/typescript/5.5/package.json +0 -1
  101. package/.config/configstore/update-notifier-npm.json +0 -4
  102. package/.gitattributes +0 -2
  103. package/Extra/Balancer.js +0 -49
  104. package/Extra/Bypass/956/index.js +0 -234
  105. package/Extra/Bypass/test/aaaa.json +0 -170
  106. package/Extra/Bypass/test/index.js +0 -188
  107. package/Extra/Database/index.js +0 -469
  108. package/Extra/ExtraAddons.js +0 -82
  109. package/Extra/ExtraFindUID.js +0 -62
  110. package/Extra/ExtraGetThread.js +0 -365
  111. package/Extra/ExtraScreenShot.js +0 -430
  112. package/Extra/ExtraUptimeRobot.js +0 -38
  113. package/Extra/Html/Classic/script.js +0 -119
  114. package/Extra/Html/Classic/style.css +0 -8
  115. package/Extra/Security/AES_256_GCM/index.js +0 -0
  116. package/Extra/Security/Base/Step_1.js +0 -6
  117. package/Extra/Security/Base/Step_2.js +0 -22
  118. package/Extra/Security/Base/Step_3.js +0 -22
  119. package/Extra/Security/Base/index.js +0 -191
  120. package/Extra/Security/Index.js +0 -5
  121. package/Extra/Security/Step_1.js +0 -6
  122. package/Extra/Security/Step_2.js +0 -22
  123. package/Extra/Security/Step_3.js +0 -22
  124. package/Extra/Src/Change_Environment.js +0 -24
  125. package/Extra/Src/Check_Update.js +0 -67
  126. package/Extra/Src/History.js +0 -115
  127. package/Extra/Src/Instant_Update.js +0 -65
  128. package/Extra/Src/Last-Run.js +0 -65
  129. package/Extra/Src/Premium.js +0 -81
  130. package/Extra/Src/Release_Memory.js +0 -160
  131. package/Extra/Src/Websocket.js +0 -213
  132. package/Extra/Src/image/checkmate.jpg +0 -0
  133. package/Extra/Src/test.js +0 -28
  134. package/Extra/Src/uuid.js +0 -137
  135. package/Func/AcceptAgreement.js +0 -31
  136. package/Func/ClearCache.js +0 -64
  137. package/Func/ReportV1.js +0 -54
  138. package/LICENSE +0 -678
  139. package/Language/index.json +0 -228
  140. package/Main.js +0 -1444
  141. package/SECURITY.md +0 -18
  142. package/broadcast.js +0 -44
  143. package/logger.js +0 -66
  144. package/src/Dev_Horizon_Data.js +0 -125
  145. package/src/Dev_getThreadInfoOLD.js +0 -422
  146. package/src/Dev_shareTest2.js +0 -68
  147. package/src/Dev_shareTest3.js +0 -71
  148. package/src/Premium.js +0 -25
  149. package/src/Screenshot.js +0 -83
  150. package/src/getAccessToken.js +0 -28
  151. package/src/getThreadInfoOLD.js +0 -422
  152. package/src/getThreadMain.js +0 -220
  153. package/src/getUserInfoMain.js +0 -65
  154. package/src/getUserInfoV2.js +0 -32
  155. package/src/getUserInfoV3.js +0 -63
  156. package/src/getUserInfoV4.js +0 -55
  157. package/src/getUserInfoV5.js +0 -61
  158. package/src/listenMqttV1.js +0 -846
  159. package/src/sendMqttMessage.js +0 -71
  160. package/src/unsendMqttMessage.js +0 -66
  161. package/test/Database_Test.js +0 -4
  162. package/test/Db2.js +0 -530
  163. package/test/Shankar_Database/A_README.md +0 -1
  164. package/test/Shankar_Database/Database.db +0 -0
  165. package/test/env/.env +0 -0
  166. package/test/example-db.db +0 -0
  167. package/test/memoryleak.js +0 -18
  168. package/test/testname.js +0 -1342
  169. package/test/testv2.js +0 -3
@@ -1,33 +1,40 @@
1
1
  "use strict";
2
2
 
3
- var utils = require("../utils");
4
- var log = require("npmlog");
5
- var bluebird = require("bluebird");
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
6
5
 
7
6
  module.exports = function (defaultFuncs, api, ctx) {
8
7
  function handleUpload(image, callback) {
9
- var uploads = [];
8
+ const uploads = [];
10
9
 
11
- var form = {
10
+ const form = {
12
11
  images_only: "true",
13
- "attachment[]": image
12
+ "attachment[]": image,
14
13
  };
15
14
 
16
15
  uploads.push(
17
16
  defaultFuncs
18
- .postFormData("https://upload.facebook.com/ajax/mercury/upload.php", ctx.jar, form, {})
17
+ .postFormData(
18
+ "https://upload.facebook.com/ajax/mercury/upload.php",
19
+ ctx.jar,
20
+ form,
21
+ {},
22
+ )
19
23
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
20
24
  .then(function (resData) {
21
- if (resData.error) throw resData;
25
+ if (resData.error) {
26
+ throw resData;
27
+ }
22
28
 
23
29
  return resData.payload.metadata[0];
24
- })
30
+ }),
25
31
  );
26
32
 
27
33
  // resolve all promises
28
- bluebird
29
- .all(uploads)
30
- .then(resData => callback(null, resData))
34
+ Promise.all(uploads)
35
+ .then(function (resData) {
36
+ callback(null, resData);
37
+ })
31
38
  .catch(function (err) {
32
39
  log.error("handleUpload", err);
33
40
  return callback(err);
@@ -35,27 +42,39 @@ module.exports = function (defaultFuncs, api, ctx) {
35
42
  }
36
43
 
37
44
  return function changeGroupImage(image, threadID, callback) {
38
- if (!callback && (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction")) throw { error: "please pass a threadID as a second argument." };
45
+ if (
46
+ !callback &&
47
+ (utils.getType(threadID) === "Function" ||
48
+ utils.getType(threadID) === "AsyncFunction")
49
+ ) {
50
+ throw { error: "please pass a threadID as a second argument." };
51
+ }
52
+
53
+ if (!utils.isReadableStream(image)) {
54
+ throw { error: "please pass a readable stream as a first argument." };
55
+ }
39
56
 
40
- var resolveFunc = function () { };
41
- var rejectFunc = function () { };
42
- var returnPromise = new Promise(function (resolve, reject) {
57
+ let resolveFunc = function () {};
58
+ let rejectFunc = function () {};
59
+ const returnPromise = new Promise(function (resolve, reject) {
43
60
  resolveFunc = resolve;
44
61
  rejectFunc = reject;
45
62
  });
46
63
 
47
64
  if (!callback) {
48
65
  callback = function (err) {
49
- if (err) return rejectFunc(err);
66
+ if (err) {
67
+ return rejectFunc(err);
68
+ }
50
69
  resolveFunc();
51
70
  };
52
71
  }
53
72
 
54
- var messageAndOTID = utils.generateOfflineThreadingID();
55
- var form = {
73
+ const messageAndOTID = utils.generateOfflineThreadingID();
74
+ const form = {
56
75
  client: "mercury",
57
76
  action_type: "ma-type:log-message",
58
- author: "fbid:" + ctx.userID,
77
+ author: "fbid:" + (ctx.i_userID || ctx.userID),
59
78
  author_email: "",
60
79
  ephemeral_ttl_mode: "0",
61
80
  is_filtered_content: false,
@@ -78,21 +97,31 @@ module.exports = function (defaultFuncs, api, ctx) {
78
97
  timestamp: Date.now(),
79
98
  timestamp_absolute: "Today",
80
99
  timestamp_relative: utils.generateTimestampRelative(),
81
- timestamp_time_passed: "0"
100
+ timestamp_time_passed: "0",
82
101
  };
83
102
 
84
103
  handleUpload(image, function (err, payload) {
85
- if (err) return callback(err);
104
+ if (err) {
105
+ return callback(err);
106
+ }
86
107
 
87
108
  form["thread_image_id"] = payload[0]["image_id"];
88
109
  form["thread_id"] = threadID;
89
110
 
90
111
  defaultFuncs
91
- .post("https://www.facebook.com/messaging/set_thread_image/", ctx.jar, form)
112
+ .post(
113
+ "https://www.facebook.com/messaging/set_thread_image/",
114
+ ctx.jar,
115
+ form,
116
+ )
92
117
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
93
118
  .then(function (resData) {
94
119
  // check for errors here
95
- if (resData.error) throw resData;
120
+
121
+ if (resData.error) {
122
+ throw resData;
123
+ }
124
+
96
125
  return callback();
97
126
  })
98
127
  .catch(function (err) {
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ var utils = require('./../utils.js');
4
+ var log = require('npmlog');
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function changeName(input, format, callback) {
8
+ var cb;
9
+ var rt = new Promise(function (resolve, reject) {
10
+ cb = error => error ? reject(error) : resolve();
11
+ });
12
+
13
+ if (typeof input == 'function') {
14
+ callback = input;
15
+ input = null;
16
+ }
17
+ if (typeof format == 'function') {
18
+ callback = format;
19
+ format = 'complete';
20
+ }
21
+ if (typeof callback == 'function') cb = callback;
22
+ if (utils.getType(input) != 'Object') {
23
+ var error = 'name must be an object, not ' + utils.getType(input);
24
+ log('changeName', error);
25
+ return cb(error);
26
+ }
27
+
28
+ var { first_name, middle_name, last_name } = input;
29
+ if (!first_name || !last_name) {
30
+ log.error('changeName', 'name is not be accepted');
31
+ return cb('name is not be accepted');
32
+ }
33
+
34
+ middle_name = middle_name || '';
35
+
36
+ var full_name =
37
+ format == 'complete' ? last_name + ' ' + (middle_name != '' ? middle_name + ' ' : '') + first_name :
38
+ format == 'standard' ? last_name + ' ' + first_name :
39
+ format == 'reversed' ? first_name + ' ' + (middle_name != '' ? middle_name + ' ' : '') + last_name :
40
+ last_name + ' ' + (middle_name != '' ? middle_name + ' ' : '') + first_name;
41
+
42
+ var form = {
43
+ fb_api_caller_class: 'RelayModern',
44
+ fb_api_req_friendly_name: 'useFXIMUpdateNameMutation',
45
+ variables: JSON.stringify({
46
+ client_mutation_id: utils.getGUID(),
47
+ family_device_id: "device_id_fetch_datr",
48
+ identity_ids: [ctx.userID],
49
+ full_name,
50
+ first_name,
51
+ middle_name,
52
+ last_name,
53
+ interface: 'FB_WEB'
54
+ }),
55
+ server_timestamps: true,
56
+ doc_id: '5763510853763960'
57
+ }
58
+
59
+ defaultFuncs
60
+ .post('https://accountscenter.facebook.com/api/graphql/', ctx.jar, form, null, null, {
61
+ Origin: 'https://accountscenter.facebook.com',
62
+ Referer: `https://accountscenter.facebook.com/profiles/${ctx.userID}/name`
63
+ })
64
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
65
+ .then(function (res) {
66
+ if (res.errors)
67
+ throw res;
68
+ else if (res.data.fxim_update_identity_name.error)
69
+ throw res.data.fxim_update_identity_name.error;
70
+ return cb();
71
+ })
72
+ .catch(function (err) {
73
+ log.error('changeName', err);
74
+ return cb(err);
75
+ });
76
+
77
+ return rt;
78
+ }
79
+ }
@@ -1,37 +1,51 @@
1
1
  "use strict";
2
2
 
3
- var utils = require("../utils");
4
- var log = require("npmlog");
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
5
 
6
6
  module.exports = function (defaultFuncs, api, ctx) {
7
7
  return function changeNickname(nickname, threadID, participantID, callback) {
8
- var resolveFunc = function () { };
9
- var rejectFunc = function () { };
10
- var returnPromise = new Promise(function (resolve, reject) {
8
+ let resolveFunc = function () {};
9
+ let rejectFunc = function () {};
10
+ const returnPromise = new Promise(function (resolve, reject) {
11
11
  resolveFunc = resolve;
12
12
  rejectFunc = reject;
13
13
  });
14
14
  if (!callback) {
15
15
  callback = function (err) {
16
- if (err) return rejectFunc(err);
16
+ if (err) {
17
+ return rejectFunc(err);
18
+ }
17
19
  resolveFunc();
18
20
  };
19
21
  }
20
22
 
21
- var form = {
23
+ const form = {
22
24
  nickname: nickname,
23
25
  participant_id: participantID,
24
- thread_or_other_fbid: threadID
26
+ thread_or_other_fbid: threadID,
25
27
  };
26
28
 
27
29
  defaultFuncs
28
- .post("https://www.facebook.com/messaging/save_thread_nickname/?source=thread_settings&dpr=1", ctx.jar, form)
30
+ .post(
31
+ "https://www.facebook.com/messaging/save_thread_nickname/?source=thread_settings&dpr=1",
32
+ ctx.jar,
33
+ form,
34
+ )
29
35
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
30
36
  .then(function (resData) {
31
- if (resData.error === 1545014) throw { error: "Trying to change nickname of user isn't in thread" };
32
- if (resData.error === 1357031) throw { error: "Trying to change user nickname of a thread that doesn't exist. Have at least one message in the thread before trying to change the user nickname." };
33
-
34
- if (resData.error) throw resData;
37
+ if (resData.error === 1545014) {
38
+ throw { error: "Trying to change nickname of user isn't in thread" };
39
+ }
40
+ if (resData.error === 1357031) {
41
+ throw {
42
+ error:
43
+ "Trying to change user nickname of a thread that doesn't exist. Have at least one message in the thread before trying to change the user nickname.",
44
+ };
45
+ }
46
+ if (resData.error) {
47
+ throw resData;
48
+ }
35
49
 
36
50
  return callback();
37
51
  })
@@ -1,31 +1,32 @@
1
1
  "use strict";
2
2
 
3
- var utils = require("../utils");
4
- var log = require("npmlog");
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
5
 
6
6
  module.exports = function (defaultFuncs, api, ctx) {
7
7
  return function changeThreadColor(color, threadID, callback) {
8
- var resolveFunc = function () { };
9
- var rejectFunc = function () { };
10
- var returnPromise = new Promise(function (resolve, reject) {
8
+ let resolveFunc = function () {};
9
+ let rejectFunc = function () {};
10
+ const returnPromise = new Promise(function (resolve, reject) {
11
11
  resolveFunc = resolve;
12
12
  rejectFunc = reject;
13
13
  });
14
14
 
15
15
  if (!callback) {
16
16
  callback = function (err) {
17
- if (err) return rejectFunc(err);
17
+ if (err) {
18
+ return rejectFunc(err);
19
+ }
18
20
  resolveFunc(err);
19
21
  };
20
22
  }
21
23
 
22
- var validatedColor = color !== null ? color.toLowerCase() : color; // API only accepts lowercase letters in hex string
23
- var colorList = Object.keys(api.threadColors).map(function (name) {
24
- return api.threadColors[name];
25
- });
26
- if (!colorList.includes(validatedColor)) throw { error: "The color you are trying to use is not a valid thread color. Use api.threadColors to find acceptable values." };
24
+ if (!isNaN(color)) {
25
+ color = color.toString();
26
+ }
27
+ const validatedColor = color !== null ? color.toLowerCase() : color; // API only accepts lowercase letters in hex string
27
28
 
28
- var form = {
29
+ const form = {
29
30
  dpr: 1,
30
31
  queries: JSON.stringify({
31
32
  o0: {
@@ -33,22 +34,24 @@ module.exports = function (defaultFuncs, api, ctx) {
33
34
  doc_id: "1727493033983591",
34
35
  query_params: {
35
36
  data: {
36
- actor_id: ctx.userID,
37
+ actor_id: ctx.i_userID || ctx.userID,
37
38
  client_mutation_id: "0",
38
39
  source: "SETTINGS",
39
40
  theme_id: validatedColor,
40
- thread_id: threadID
41
- }
42
- }
43
- }
44
- })
41
+ thread_id: threadID,
42
+ },
43
+ },
44
+ },
45
+ }),
45
46
  };
46
47
 
47
48
  defaultFuncs
48
49
  .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
49
50
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
50
51
  .then(function (resData) {
51
- if (resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
52
+ if (resData[resData.length - 1].error_results > 0) {
53
+ throw new utils.CustomError(resData[0].o0.errors);
54
+ }
52
55
 
53
56
  return callback();
54
57
  })
@@ -1,34 +1,47 @@
1
1
  "use strict";
2
2
 
3
- var utils = require("../utils");
4
- var log = require("npmlog");
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
5
 
6
6
  module.exports = function (defaultFuncs, api, ctx) {
7
7
  return function changeThreadEmoji(emoji, threadID, callback) {
8
- var resolveFunc = function () { };
9
- var rejectFunc = function () { };
10
- var returnPromise = new Promise(function (resolve, reject) {
8
+ let resolveFunc = function () {};
9
+ let rejectFunc = function () {};
10
+ const returnPromise = new Promise(function (resolve, reject) {
11
11
  resolveFunc = resolve;
12
12
  rejectFunc = reject;
13
13
  });
14
14
 
15
15
  if (!callback) {
16
16
  callback = function (err) {
17
- if (err) return rejectFunc(err);
17
+ if (err) {
18
+ return rejectFunc(err);
19
+ }
18
20
  resolveFunc();
19
21
  };
20
22
  }
21
- var form = {
23
+ const form = {
22
24
  emoji_choice: emoji,
23
- thread_or_other_fbid: threadID
25
+ thread_or_other_fbid: threadID,
24
26
  };
25
27
 
26
28
  defaultFuncs
27
- .post("https://www.facebook.com/messaging/save_thread_emoji/?source=thread_settings&__pc=EXP1%3Amessengerdotcom_pkg", ctx.jar, form)
29
+ .post(
30
+ "https://www.facebook.com/messaging/save_thread_emoji/?source=thread_settings&__pc=EXP1%3Amessengerdotcom_pkg",
31
+ ctx.jar,
32
+ form,
33
+ )
28
34
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
29
35
  .then(function (resData) {
30
- if (resData.error === 1357031) throw { error: "Trying to change emoji of a chat that doesn't exist. Have at least one message in the thread before trying to change the emoji." };
31
- if (resData.error) throw resData;
36
+ if (resData.error === 1357031) {
37
+ throw {
38
+ error:
39
+ "Trying to change emoji of a chat that doesn't exist. Have at least one message in the thread before trying to change the emoji.",
40
+ };
41
+ }
42
+ if (resData.error) {
43
+ throw resData;
44
+ }
32
45
 
33
46
  return callback();
34
47
  })
@@ -0,0 +1,59 @@
1
+ 'use strict';
2
+
3
+ var utils = require('../utils');
4
+ var log = require('npmlog');
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function changeUsername(username, callback) {
8
+ var cb;
9
+ var rt = new Promise(function (resolve, reject) {
10
+ cb = (error, info) => info ? resolve(info) : reject(error);
11
+ });
12
+
13
+ if (typeof username == 'function') {
14
+ var error = 'username must be a string, and not ' + utils.getType(username);
15
+ log.error('changeUsername', error);
16
+ return username(error);
17
+ }
18
+ if (typeof callback == 'function') cb = callback;
19
+ if (typeof username != 'string') {
20
+ var error = 'username must be a string, and not ' + utils.getType(username);
21
+ log.error('changeUsername', error);
22
+ return cb(error);
23
+ }
24
+
25
+ var form = {
26
+ fb_api_caller_class: 'RelayModern',
27
+ fb_api_req_friendly_name: 'useFXIMUpdateUsernameMutation',
28
+ variables: JSON.stringify({
29
+ client_mutation_id: utils.getGUID(),
30
+ family_device_id: "device_id_fetch_datr",
31
+ identity_ids: [ctx.userID],
32
+ username,
33
+ interface: "FB_WEB"
34
+ }),
35
+ server_timestamps: true,
36
+ doc_id: 5737739449613305
37
+ }
38
+
39
+ defaultFuncs
40
+ .post('https://accountscenter.facebook.com/api/graphql/', ctx.jar, form, null, null, {
41
+ Origin: 'https://accountscenter.facebook.com',
42
+ Referer: `https://accountscenter.facebook.com/profiles/${ctx.userID}/username/?entrypoint=fb_account_center`
43
+ })
44
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
45
+ .then(function (res) {
46
+ if (res.errors)
47
+ throw res;
48
+ else if (res.data.fxim_update_identity_username.error)
49
+ throw res.data.fxim_update_identity_username.error;
50
+ return cb();
51
+ })
52
+ .catch(function (err) {
53
+ log.error('changeUsername', err);
54
+ return cb(err);
55
+ });
56
+
57
+ return rt;
58
+ }
59
+ }