@cexy/hoonfca 1.0.7 → 2.0.1

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 (191) hide show
  1. package/LICENSE +3 -0
  2. package/examples/login-with-cookies.js +102 -0
  3. package/examples/verify.js +70 -0
  4. package/index.js +2 -8
  5. package/package.json +82 -61
  6. package/src/{api/action → apis}/addExternalModule.js +24 -25
  7. package/src/apis/addUserToGroup.js +108 -0
  8. package/src/apis/changeAdminStatus.js +148 -0
  9. package/src/apis/changeArchivedStatus.js +61 -0
  10. package/src/apis/changeAvatar.js +103 -0
  11. package/src/apis/changeBio.js +69 -0
  12. package/src/apis/changeBlockedStatus.js +54 -0
  13. package/src/apis/changeGroupImage.js +136 -0
  14. package/src/apis/changeThreadColor.js +116 -0
  15. package/src/apis/changeThreadEmoji.js +53 -0
  16. package/src/apis/comment.js +207 -0
  17. package/src/apis/createAITheme.js +129 -0
  18. package/src/apis/createNewGroup.js +79 -0
  19. package/src/apis/createPoll.js +73 -0
  20. package/src/apis/deleteMessage.js +44 -0
  21. package/src/apis/deleteThread.js +52 -0
  22. package/src/apis/e2ee.js +17 -0
  23. package/src/apis/editMessage.js +70 -0
  24. package/src/apis/emoji.js +124 -0
  25. package/src/apis/fetchThemeData.js +82 -0
  26. package/src/apis/follow.js +81 -0
  27. package/src/apis/forwardMessage.js +52 -0
  28. package/src/apis/friend.js +243 -0
  29. package/src/apis/gcmember.js +122 -0
  30. package/src/apis/gcname.js +123 -0
  31. package/src/apis/gcrule.js +119 -0
  32. package/src/apis/getAccess.js +111 -0
  33. package/src/apis/getBotInfo.js +88 -0
  34. package/src/apis/getBotInitialData.js +43 -0
  35. package/src/apis/getFriendsList.js +79 -0
  36. package/src/apis/getMessage.js +423 -0
  37. package/src/apis/getTheme.js +95 -0
  38. package/src/apis/getThemeInfo.js +116 -0
  39. package/src/apis/getThreadHistory.js +239 -0
  40. package/src/apis/getThreadInfo.js +267 -0
  41. package/src/apis/getThreadList.js +232 -0
  42. package/src/apis/getThreadPictures.js +58 -0
  43. package/src/apis/getUserID.js +117 -0
  44. package/src/apis/getUserInfo.js +513 -0
  45. package/src/{api/users → apis}/getUserInfoV2.js +146 -134
  46. package/src/apis/handleMessageRequest.js +50 -0
  47. package/src/apis/httpGet.js +63 -0
  48. package/src/apis/httpPost.js +89 -0
  49. package/src/apis/httpPostFormData.js +69 -0
  50. package/src/apis/listenMqtt.js +1236 -0
  51. package/src/apis/listenSpeed.js +179 -0
  52. package/src/apis/logout.js +87 -0
  53. package/src/apis/markAsDelivered.js +47 -0
  54. package/src/{api/messaging → apis}/markAsRead.js +99 -88
  55. package/src/apis/markAsReadAll.js +40 -0
  56. package/src/apis/markAsSeen.js +70 -0
  57. package/src/apis/mqttDeltaValue.js +278 -0
  58. package/src/apis/muteThread.js +45 -0
  59. package/src/apis/nickname.js +132 -0
  60. package/src/apis/notes.js +163 -0
  61. package/src/apis/pinMessage.js +150 -0
  62. package/src/apis/produceMetaTheme.js +180 -0
  63. package/src/apis/realtime.js +182 -0
  64. package/src/apis/removeUserFromGroup.js +117 -0
  65. package/src/apis/resolvePhotoUrl.js +58 -0
  66. package/src/apis/searchForThread.js +154 -0
  67. package/src/apis/sendMessage.js +354 -0
  68. package/src/apis/sendMessageMqtt.js +249 -0
  69. package/src/apis/sendTypingIndicator.js +91 -0
  70. package/src/apis/setMessageReaction.js +27 -0
  71. package/src/apis/setMessageReactionMqtt.js +61 -0
  72. package/src/apis/setThreadTheme.js +260 -0
  73. package/src/apis/setThreadThemeMqtt.js +94 -0
  74. package/src/apis/share.js +107 -0
  75. package/src/apis/shareContact.js +66 -0
  76. package/src/apis/stickers.js +257 -0
  77. package/src/apis/story.js +181 -0
  78. package/src/apis/theme.js +233 -0
  79. package/src/apis/unfriend.js +47 -0
  80. package/src/apis/unsendMessage.js +17 -0
  81. package/src/engine/client.js +92 -0
  82. package/src/engine/models/buildAPI.js +152 -0
  83. package/src/engine/models/loginHelper.js +519 -0
  84. package/src/engine/models/setOptions.js +88 -0
  85. package/src/security/e2ee.js +109 -0
  86. package/src/types/index.d.ts +498 -0
  87. package/src/utils/antiSuspension.js +506 -0
  88. package/src/utils/auth-helpers.js +149 -0
  89. package/src/utils/autoReLogin.js +336 -0
  90. package/src/utils/axios.js +436 -0
  91. package/src/utils/cache.js +54 -0
  92. package/src/utils/clients.js +282 -0
  93. package/src/utils/constants.js +410 -23
  94. package/src/utils/formatters/data/formatAttachment.js +370 -0
  95. package/src/utils/formatters/data/formatDelta.js +109 -0
  96. package/src/utils/formatters/index.js +159 -0
  97. package/src/utils/formatters/value/formatCookie.js +91 -0
  98. package/src/utils/formatters/value/formatDate.js +36 -0
  99. package/src/utils/formatters/value/formatID.js +16 -0
  100. package/src/utils/formatters.js +1373 -0
  101. package/src/utils/headers.js +214 -99
  102. package/src/utils/index.js +153 -0
  103. package/src/utils/monitoring.js +333 -0
  104. package/src/utils/rateLimiter.js +319 -0
  105. package/src/utils/tokenRefresh.js +657 -0
  106. package/src/utils/user-agents.js +238 -0
  107. package/src/utils/validation.js +157 -0
  108. package/CHANGELOG.md +0 -181
  109. package/DOCS.md +0 -2636
  110. package/LICENSE-MIT +0 -21
  111. package/README.md +0 -632
  112. package/func/checkUpdate.js +0 -233
  113. package/func/logger.js +0 -48
  114. package/index.d.ts +0 -746
  115. package/module/config.js +0 -67
  116. package/module/login.js +0 -154
  117. package/module/loginHelper.js +0 -1034
  118. package/module/options.js +0 -54
  119. package/src/api/action/changeAvatar.js +0 -137
  120. package/src/api/action/changeBio.js +0 -75
  121. package/src/api/action/enableAutoSaveAppState.js +0 -73
  122. package/src/api/action/getCurrentUserID.js +0 -7
  123. package/src/api/action/handleFriendRequest.js +0 -57
  124. package/src/api/action/logout.js +0 -76
  125. package/src/api/action/refreshFb_dtsg.js +0 -48
  126. package/src/api/action/setPostReaction.js +0 -106
  127. package/src/api/action/unfriend.js +0 -54
  128. package/src/api/http/httpGet.js +0 -46
  129. package/src/api/http/httpPost.js +0 -52
  130. package/src/api/http/postFormData.js +0 -47
  131. package/src/api/messaging/addUserToGroup.js +0 -68
  132. package/src/api/messaging/changeAdminStatus.js +0 -122
  133. package/src/api/messaging/changeArchivedStatus.js +0 -55
  134. package/src/api/messaging/changeBlockedStatus.js +0 -48
  135. package/src/api/messaging/changeGroupImage.js +0 -90
  136. package/src/api/messaging/changeNickname.js +0 -70
  137. package/src/api/messaging/changeThreadColor.js +0 -79
  138. package/src/api/messaging/changeThreadEmoji.js +0 -106
  139. package/src/api/messaging/createNewGroup.js +0 -88
  140. package/src/api/messaging/createPoll.js +0 -43
  141. package/src/api/messaging/createThemeAI.js +0 -98
  142. package/src/api/messaging/deleteMessage.js +0 -56
  143. package/src/api/messaging/deleteThread.js +0 -56
  144. package/src/api/messaging/editMessage.js +0 -68
  145. package/src/api/messaging/forwardAttachment.js +0 -51
  146. package/src/api/messaging/getEmojiUrl.js +0 -29
  147. package/src/api/messaging/getFriendsList.js +0 -82
  148. package/src/api/messaging/getMessage.js +0 -829
  149. package/src/api/messaging/getThemePictures.js +0 -62
  150. package/src/api/messaging/handleMessageRequest.js +0 -65
  151. package/src/api/messaging/markAsDelivered.js +0 -57
  152. package/src/api/messaging/markAsReadAll.js +0 -49
  153. package/src/api/messaging/markAsSeen.js +0 -61
  154. package/src/api/messaging/muteThread.js +0 -50
  155. package/src/api/messaging/removeUserFromGroup.js +0 -106
  156. package/src/api/messaging/resolvePhotoUrl.js +0 -43
  157. package/src/api/messaging/scheduler.js +0 -264
  158. package/src/api/messaging/searchForThread.js +0 -52
  159. package/src/api/messaging/sendMessage.js +0 -272
  160. package/src/api/messaging/sendTypingIndicator.js +0 -67
  161. package/src/api/messaging/setMessageReaction.js +0 -76
  162. package/src/api/messaging/setTitle.js +0 -119
  163. package/src/api/messaging/shareContact.js +0 -49
  164. package/src/api/messaging/threadColors.js +0 -128
  165. package/src/api/messaging/unsendMessage.js +0 -81
  166. package/src/api/messaging/uploadAttachment.js +0 -94
  167. package/src/api/socket/core/connectMqtt.js +0 -255
  168. package/src/api/socket/core/emitAuth.js +0 -106
  169. package/src/api/socket/core/getSeqID.js +0 -40
  170. package/src/api/socket/core/getTaskResponseData.js +0 -22
  171. package/src/api/socket/core/markDelivery.js +0 -12
  172. package/src/api/socket/core/parseDelta.js +0 -391
  173. package/src/api/socket/detail/buildStream.js +0 -208
  174. package/src/api/socket/detail/constants.js +0 -24
  175. package/src/api/socket/listenMqtt.js +0 -364
  176. package/src/api/socket/middleware/index.js +0 -216
  177. package/src/api/threads/getThreadHistory.js +0 -664
  178. package/src/api/threads/getThreadInfo.js +0 -438
  179. package/src/api/threads/getThreadList.js +0 -293
  180. package/src/api/threads/getThreadPictures.js +0 -78
  181. package/src/api/users/getUserID.js +0 -65
  182. package/src/api/users/getUserInfo.js +0 -327
  183. package/src/core/sendReqMqtt.js +0 -96
  184. package/src/database/models/index.js +0 -87
  185. package/src/database/models/thread.js +0 -45
  186. package/src/database/models/user.js +0 -46
  187. package/src/database/threadData.js +0 -98
  188. package/src/database/userData.js +0 -89
  189. package/src/utils/client.js +0 -320
  190. package/src/utils/format.js +0 -1115
  191. package/src/utils/request.js +0 -305
@@ -1,134 +1,146 @@
1
- "use strict";
2
-
3
- const { parseAndCheckLogin } = require("../../utils/client.js");
4
- const logger = require("../../../func/logger");
5
- const DEFAULT_DOC_ID = "24418640587785718";
6
- const DEFAULT_FRIENDLY_NAME = "CometHovercardQueryRendererQuery";
7
- const DEFAULT_CALLER_CLASS = "RelayModern";
8
-
9
- function toJSONMaybe(s) {
10
- if (!s) return null;
11
- if (typeof s === "string") {
12
- const t = s.trim().replace(/^for\s*\(\s*;\s*;\s*\)\s*;/, "");
13
- try { return JSON.parse(t); } catch { return null; }
14
- }
15
- return s;
16
- }
17
-
18
- function usernameFromUrl(raw) {
19
- if (!raw) return null;
20
- try {
21
- const u = new URL(raw);
22
- if (/^www\.facebook\.com$/i.test(u.hostname)) {
23
- const seg = u.pathname.replace(/^\//, "").replace(/\/$/, "");
24
- if (seg && !/^profile\.php$/i.test(seg) && !seg.includes("/")) return seg;
25
- }
26
- } catch { }
27
- return null;
28
- }
29
-
30
- function pickMeta(u) {
31
- let friendshipStatus = null;
32
- let gender = null;
33
- let shortName = u?.short_name || null;
34
- const pa = Array.isArray(u?.primaryActions) ? u.primaryActions : [];
35
- const sa = Array.isArray(u?.secondaryActions) ? u.secondaryActions : [];
36
- const aFriend = pa.find(x => x?.profile_action_type === "FRIEND");
37
- if (aFriend?.client_handler?.profile_action?.restrictable_profile_owner) {
38
- const p = aFriend.client_handler.profile_action.restrictable_profile_owner;
39
- friendshipStatus = p?.friendship_status || null;
40
- gender = p?.gender || gender;
41
- shortName = p?.short_name || shortName;
42
- }
43
- if (!gender || !shortName) {
44
- const aBlock = sa.find(x => x?.profile_action_type === "BLOCK");
45
- const p2 = aBlock?.client_handler?.profile_action?.profile_owner;
46
- if (p2) {
47
- gender = p2.gender || gender;
48
- shortName = p2.short_name || shortName;
49
- }
50
- }
51
- return { friendshipStatus, gender, shortName };
52
- }
53
-
54
- function normalizeUser(u) {
55
- if (!u) return null;
56
- const vanity = usernameFromUrl(u.profile_url || u.url);
57
- const meta = pickMeta(u);
58
- return {
59
- id: u.id || null,
60
- name: u.name || null,
61
- username: vanity || u.username_for_profile || null,
62
- profileUrl: u.profile_url || u.url || null,
63
- url: u.url || null,
64
- isVerified: !!u.is_verified,
65
- isMemorialized: !!u.is_visibly_memorialized,
66
- avatar: u.profile_picture?.uri || null,
67
- shortName: meta.shortName || null,
68
- gender: meta.gender || null,
69
- friendshipStatus: meta.friendshipStatus || null
70
- };
71
- }
72
-
73
- function toRetObjEntry(nu) {
74
- return {
75
- name: nu?.name || null,
76
- firstName: nu?.shortName || null,
77
- vanity: nu?.username || null,
78
- thumbSrc: nu?.avatar || null,
79
- profileUrl: nu?.profileUrl || null,
80
- gender: nu?.gender || null,
81
- type: "User",
82
- isFriend: nu?.friendshipStatus === "ARE_FRIENDS",
83
- isMessengerUser: null,
84
- isMessageBlockedByViewer: false,
85
- workInfo: null,
86
- messengerStatus: null
87
- };
88
- }
89
-
90
- module.exports = function (defaultFuncs, api, ctx) {
91
- async function fetchOne(uid) {
92
- const av = String(ctx?.userID || "");
93
- const variablesObj = {
94
- actionBarRenderLocation: "WWW_COMET_HOVERCARD",
95
- context: "DEFAULT",
96
- entityID: String(uid),
97
- scale: 1,
98
- __relay_internal__pv__WorkCometIsEmployeeGKProviderrelayprovider: false
99
- };
100
- const form = {
101
- av,
102
- fb_api_caller_class: DEFAULT_CALLER_CLASS,
103
- fb_api_req_friendly_name: DEFAULT_FRIENDLY_NAME,
104
- server_timestamps: true,
105
- doc_id: DEFAULT_DOC_ID,
106
- variables: JSON.stringify(variablesObj)
107
- };
108
- const raw = await defaultFuncs.post("https://www.facebook.com/api/graphql/", null, form).then(parseAndCheckLogin(ctx, defaultFuncs));
109
- const parsed = toJSONMaybe(raw) ?? raw;
110
- const root = Array.isArray(parsed) ? parsed[0] : parsed;
111
- const user = root?.data?.node?.comet_hovercard_renderer?.user || null;
112
- return normalizeUser(user);
113
- }
114
-
115
- return function getUserInfoV2(idOrList, callback) {
116
- let resolveFunc, rejectFunc;
117
- const returnPromise = new Promise((resolve, reject) => { resolveFunc = resolve; rejectFunc = reject; });
118
- if (typeof callback !== "function") {
119
- callback = (err, data) => { if (err) return rejectFunc(err); resolveFunc(data); };
120
- }
121
- const ids = Array.isArray(idOrList) ? idOrList.map(v => String(v)) : [String(idOrList)];
122
- Promise.allSettled(ids.map(fetchOne))
123
- .then(results => {
124
- const retObj = {};
125
- for (let i = 0; i < ids.length; i++) {
126
- const nu = results[i].status === "fulfilled" ? results[i].value : null;
127
- retObj[ids[i]] = toRetObjEntry(nu);
128
- }
129
- return callback(null, retObj);
130
- })
131
- .catch(err => { logger("getUserInfoV2" + err, "error"); callback(err); });
132
- return returnPromise;
133
- };
134
- };
1
+ "use strict";
2
+
3
+ const utils = require('../utils');
4
+
5
+ const DOC_V2 = "24418640587785718";
6
+ const FRIENDLY_V2 = "CometHovercardQueryRendererQuery";
7
+ const CALLER_V2 = "RelayModern";
8
+
9
+ function toJSONMaybe(s) {
10
+ if (!s) return null;
11
+ if (typeof s === "string") {
12
+ const t = s.trim().replace(/^for\s*\(\s*;\s*;\s*\)\s*;/, "");
13
+ try { return JSON.parse(t); } catch { return null; }
14
+ }
15
+ return s;
16
+ }
17
+
18
+ function usernameFromUrl(raw) {
19
+ if (!raw) return null;
20
+ try {
21
+ const u = new URL(raw);
22
+ if (/^www\.facebook\.com$/i.test(u.hostname)) {
23
+ const seg = u.pathname.replace(/^\//, "").replace(/\/$/, "");
24
+ if (seg && !/^profile\.php$/i.test(seg) && !seg.includes("/")) return seg;
25
+ }
26
+ } catch { }
27
+ return null;
28
+ }
29
+
30
+ function pickMeta(u) {
31
+ let friendshipStatus = null;
32
+ let gender = null;
33
+ let shortName = u?.short_name || null;
34
+ const pa = Array.isArray(u?.primaryActions) ? u.primaryActions : [];
35
+ const sa = Array.isArray(u?.secondaryActions) ? u.secondaryActions : [];
36
+ const aFriend = pa.find(x => x?.profile_action_type === "FRIEND");
37
+ if (aFriend?.client_handler?.profile_action?.restrictable_profile_owner) {
38
+ const p = aFriend.client_handler.profile_action.restrictable_profile_owner;
39
+ friendshipStatus = p?.friendship_status || null;
40
+ gender = p?.gender || gender;
41
+ shortName = p?.short_name || shortName;
42
+ }
43
+ if (!gender || !shortName) {
44
+ const aBlock = sa.find(x => x?.profile_action_type === "BLOCK");
45
+ const p2 = aBlock?.client_handler?.profile_action?.profile_owner;
46
+ if (p2) {
47
+ gender = p2.gender || gender;
48
+ shortName = p2.short_name || shortName;
49
+ }
50
+ }
51
+ return { friendshipStatus, gender, shortName };
52
+ }
53
+
54
+ function normalizeUser(u) {
55
+ if (!u) return null;
56
+ const vanity = usernameFromUrl(u.profile_url || u.url);
57
+ const meta = pickMeta(u);
58
+ return {
59
+ id: u.id || null,
60
+ name: u.name || null,
61
+ username: vanity || u.username_for_profile || null,
62
+ profileUrl: u.profile_url || u.url || null,
63
+ url: u.url || null,
64
+ isVerified: !!u.is_verified,
65
+ isMemorialized: !!u.is_visibly_memorialized,
66
+ avatar: u.profile_picture?.uri || null,
67
+ shortName: meta.shortName || null,
68
+ gender: meta.gender || null,
69
+ friendshipStatus: meta.friendshipStatus || null
70
+ };
71
+ }
72
+
73
+ function toRetObjEntry(nu) {
74
+ return {
75
+ name: nu?.name || null,
76
+ firstName: nu?.shortName || null,
77
+ vanity: nu?.username || null,
78
+ thumbSrc: nu?.avatar || null,
79
+ profileUrl: nu?.profileUrl || null,
80
+ gender: nu?.gender || null,
81
+ type: "User",
82
+ isFriend: nu?.friendshipStatus === "ARE_FRIENDS",
83
+ isMessengerUser: null,
84
+ isMessageBlockedByViewer: false,
85
+ workInfo: null,
86
+ messengerStatus: null,
87
+ isVerified: nu?.isVerified || false,
88
+ isMemorialized: nu?.isMemorialized || false
89
+ };
90
+ }
91
+
92
+ module.exports = (defaultFuncs, api, ctx) => {
93
+ async function fetchOne(uid) {
94
+ const av = String(ctx?.userID || "");
95
+ const variablesObj = {
96
+ actionBarRenderLocation: "WWW_COMET_HOVERCARD",
97
+ context: "DEFAULT",
98
+ entityID: String(uid),
99
+ scale: 1,
100
+ __relay_internal__pv__WorkCometIsEmployeeGKProviderrelayprovider: false
101
+ };
102
+ const form = {
103
+ av,
104
+ fb_api_caller_class: CALLER_V2,
105
+ fb_api_req_friendly_name: FRIENDLY_V2,
106
+ server_timestamps: true,
107
+ doc_id: DOC_V2,
108
+ variables: JSON.stringify(variablesObj)
109
+ };
110
+ const raw = await defaultFuncs.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
111
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs));
112
+ const parsed = toJSONMaybe(raw) ?? raw;
113
+ const root = Array.isArray(parsed) ? parsed[0] : parsed;
114
+ const user = root?.data?.node?.comet_hovercard_renderer?.user || null;
115
+ return normalizeUser(user);
116
+ }
117
+
118
+ return function getUserInfoV2(idOrList, callback) {
119
+ let resolveFunc, rejectFunc;
120
+ const returnPromise = new Promise((resolve, reject) => {
121
+ resolveFunc = resolve;
122
+ rejectFunc = reject;
123
+ });
124
+ if (typeof callback !== "function") {
125
+ callback = (err, data) => {
126
+ if (err) return rejectFunc(err);
127
+ resolveFunc(data);
128
+ };
129
+ }
130
+ const ids = Array.isArray(idOrList) ? idOrList.map(v => String(v)) : [String(idOrList)];
131
+ Promise.allSettled(ids.map(fetchOne))
132
+ .then(results => {
133
+ const retObj = {};
134
+ for (let i = 0; i < ids.length; i++) {
135
+ const nu = results[i].status === "fulfilled" ? results[i].value : null;
136
+ retObj[ids[i]] = toRetObjEntry(nu);
137
+ }
138
+ return callback(null, retObj);
139
+ })
140
+ .catch(err => {
141
+ utils.error("getUserInfoV2", err);
142
+ callback(err);
143
+ });
144
+ return returnPromise;
145
+ };
146
+ };
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ const utils = require('../utils');
4
+
5
+ module.exports = (defaultFuncs, api, ctx) => {
6
+ return async function handleMessageRequest(threadID, accept, callback) {
7
+ let resolveFunc = () => {};
8
+ let rejectFunc = () => {};
9
+ const returnPromise = new Promise((resolve, reject) => {
10
+ resolveFunc = resolve;
11
+ rejectFunc = reject;
12
+ });
13
+
14
+ if (!callback) {
15
+ callback = (err, result) => {
16
+ if (err) return rejectFunc(err);
17
+ resolveFunc(result);
18
+ };
19
+ }
20
+
21
+ try {
22
+ if (utils.getType(accept) === "Function") {
23
+ callback = accept;
24
+ accept = true;
25
+ }
26
+
27
+ const form = {
28
+ ids: `ids[${threadID}]=${threadID}`,
29
+ action: accept ? "accept" : "reject"
30
+ };
31
+
32
+ const res = await defaultFuncs.post(
33
+ "https://www.facebook.com/ajax/mercury/handle_message_requests.php",
34
+ ctx.jar,
35
+ form
36
+ ).then(utils.parseAndCheckLogin(ctx, defaultFuncs));
37
+
38
+ if (res && res.error) {
39
+ throw res;
40
+ }
41
+
42
+ return callback(null, { success: true, accepted: accept });
43
+ } catch (err) {
44
+ utils.error("handleMessageRequest", err);
45
+ callback(err);
46
+ }
47
+
48
+ return returnPromise;
49
+ };
50
+ };
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ const utils = require('../utils');
4
+
5
+ module.exports = function (defaultFuncs, api, ctx) {
6
+ return function httpGet(url, form, customHeader, callback, notAPI) {
7
+ let resolveFunc = function () {};
8
+ let rejectFunc = function () {};
9
+
10
+ const returnPromise = new Promise(function (resolve, reject) {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+
15
+ if (
16
+ utils.getType(form) == "Function" ||
17
+ utils.getType(form) == "AsyncFunction"
18
+ ) {
19
+ callback = form;
20
+ form = {};
21
+ }
22
+
23
+ if (
24
+ utils.getType(customHeader) == "Function" ||
25
+ utils.getType(customHeader) == "AsyncFunction"
26
+ ) {
27
+ callback = customHeader;
28
+ customHeader = {};
29
+ }
30
+
31
+ customHeader = customHeader || {};
32
+
33
+ callback =
34
+ callback ||
35
+ function (err, data) {
36
+ if (err) return rejectFunc(err);
37
+ resolveFunc(data);
38
+ };
39
+
40
+ if (notAPI) {
41
+ utils
42
+ .get(url, ctx.jar, form, ctx.globalOptions, ctx, customHeader)
43
+ .then(function (resData) {
44
+ callback(null, resData.body.toString());
45
+ })
46
+ .catch(function (err) {
47
+ utils.error("httpGet", err);
48
+ return callback(err);
49
+ });
50
+ } else {
51
+ defaultFuncs
52
+ .get(url, ctx.jar, form, ctx, customHeader)
53
+ .then(function (resData) {
54
+ callback(null, resData.body.toString());
55
+ })
56
+ .catch(function (err) {
57
+ utils.error("httpGet", err);
58
+ return callback(err);
59
+ });
60
+ }
61
+ return returnPromise;
62
+ };
63
+ };
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+
3
+ const utils = require('../utils');
4
+
5
+ module.exports = function (defaultFuncs, api, ctx) {
6
+ return function httpPost(url, form, customHeader, callback, notAPI) {
7
+ let resolveFunc = function () {};
8
+ let rejectFunc = function () {};
9
+
10
+ const returnPromise = new Promise(function (resolve, reject) {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+
15
+ if (
16
+ utils.getType(form) == "Function" ||
17
+ utils.getType(form) == "AsyncFunction"
18
+ ) {
19
+ callback = form;
20
+ form = {};
21
+ }
22
+
23
+ if (
24
+ utils.getType(customHeader) == "Function" ||
25
+ utils.getType(customHeader) == "AsyncFunction"
26
+ ) {
27
+ callback = customHeader;
28
+ customHeader = {};
29
+ }
30
+
31
+ customHeader = customHeader || {};
32
+
33
+ callback =
34
+ callback ||
35
+ function (err, data) {
36
+ if (err) return rejectFunc(err);
37
+ resolveFunc(data);
38
+ };
39
+
40
+ const normalizeBody = function(body) {
41
+ if (body === null || body === undefined) {
42
+ return String(body);
43
+ }
44
+
45
+ if (Buffer.isBuffer(body) || body instanceof Uint8Array) {
46
+ return body.toString('utf8');
47
+ }
48
+
49
+ if (typeof body === 'string') {
50
+ return body;
51
+ }
52
+
53
+ if (typeof body === 'object') {
54
+ try {
55
+ return JSON.stringify(body);
56
+ } catch (err) {
57
+ return String(body);
58
+ }
59
+ }
60
+
61
+ return String(body);
62
+ };
63
+
64
+ if (notAPI) {
65
+ utils
66
+ .post(url, ctx.jar, form, ctx.globalOptions, ctx, customHeader)
67
+ .then(function (resData) {
68
+ const body = normalizeBody(resData.body);
69
+ callback(null, body);
70
+ })
71
+ .catch(function (err) {
72
+ utils.error("httpPost", err);
73
+ return callback(err);
74
+ });
75
+ } else {
76
+ defaultFuncs
77
+ .post(url, ctx.jar, form, ctx, customHeader)
78
+ .then(function (resData) {
79
+ const body = normalizeBody(resData.body);
80
+ callback(null, body);
81
+ })
82
+ .catch(function (err) {
83
+ utils.error("httpPost", err);
84
+ return callback(err);
85
+ });
86
+ }
87
+ return returnPromise;
88
+ };
89
+ };
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ const utils = require('../utils');
4
+
5
+ module.exports = function (defaultFuncs, api, ctx) {
6
+ return function httpPostFormData(url, form, customHeader, callback, notAPI) {
7
+ let resolveFunc = function () {};
8
+ let rejectFunc = function () {};
9
+
10
+ const returnPromise = new Promise(function (resolve, reject) {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+
15
+ if (
16
+ utils.getType(form) == "Function" ||
17
+ utils.getType(form) == "AsyncFunction"
18
+ ) {
19
+ callback = form;
20
+ form = {};
21
+ }
22
+
23
+ if (
24
+ utils.getType(customHeader) == "Function" ||
25
+ utils.getType(customHeader) == "AsyncFunction"
26
+ ) {
27
+ callback = customHeader;
28
+ customHeader = {};
29
+ }
30
+
31
+ customHeader = customHeader || {};
32
+
33
+ if (utils.getType(callback) == "Boolean") {
34
+ notAPI = callback;
35
+ callback = null;
36
+ }
37
+
38
+ callback =
39
+ callback ||
40
+ function (err, data) {
41
+ if (err) return rejectFunc(err);
42
+ resolveFunc(data);
43
+ };
44
+
45
+ if (notAPI) {
46
+ utils
47
+ .postFormData(url, ctx.jar, form, ctx.globalOptions, ctx, customHeader)
48
+ .then(function (resData) {
49
+ callback(null, resData.body.toString());
50
+ })
51
+ .catch(function (err) {
52
+ utils.error("httpPostFormData", err);
53
+ return callback(err);
54
+ });
55
+ } else {
56
+ defaultFuncs
57
+ .postFormData(url, ctx.jar, form, null, ctx)
58
+ .then(function (resData) {
59
+ callback(null, resData.body.toString());
60
+ })
61
+ .catch(function (err) {
62
+ utils.error("httpPostFormData", err);
63
+ return callback(err);
64
+ });
65
+ }
66
+
67
+ return returnPromise;
68
+ };
69
+ };