fca-nx 6.6.6

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 (196) hide show
  1. package/LICENCE +21 -0
  2. package/README.md +446 -0
  3. package/e2ee/config.json +0 -0
  4. package/e2ee/crypto.js +173 -0
  5. package/e2ee/index.js +1032 -0
  6. package/e2ee/proto/ArmadilloApplication.proto +281 -0
  7. package/e2ee/proto/ArmadilloICDC.proto +14 -0
  8. package/e2ee/proto/ConsumerApplication.proto +232 -0
  9. package/e2ee/proto/MessageApplication.proto +82 -0
  10. package/e2ee/proto/MessageTransport.proto +77 -0
  11. package/e2ee/proto/WACommon.proto +66 -0
  12. package/e2ee/proto/WAMediaTransport.proto +176 -0
  13. package/e2ee/protocol.js +196 -0
  14. package/e2ee/ratchet.js +219 -0
  15. package/e2ee/store.js +182 -0
  16. package/e2ee/vendor/fb-e2ee.cjs +9159 -0
  17. package/e2ee/vendor/proto/ArmadilloApplication.proto +281 -0
  18. package/e2ee/vendor/proto/ArmadilloICDC.proto +14 -0
  19. package/e2ee/vendor/proto/ConsumerApplication.proto +232 -0
  20. package/e2ee/vendor/proto/MessageApplication.proto +82 -0
  21. package/e2ee/vendor/proto/MessageTransport.proto +77 -0
  22. package/e2ee/vendor/proto/WACommon.proto +66 -0
  23. package/e2ee/vendor/proto/WAMediaTransport.proto +176 -0
  24. package/func/checkUpdate.js +7 -0
  25. package/func/logAdapter.js +33 -0
  26. package/func/logger.js +134 -0
  27. package/index.js +22 -0
  28. package/module/config.js +45 -0
  29. package/module/login.js +183 -0
  30. package/module/loginHelper.js +1382 -0
  31. package/module/options.js +52 -0
  32. package/package.json +101 -0
  33. package/src/api/action/addExternalModule.js +25 -0
  34. package/src/api/action/addFriend.js +145 -0
  35. package/src/api/action/changeAvatar.js +137 -0
  36. package/src/api/action/changeBio.js +75 -0
  37. package/src/api/action/changeCover.js +277 -0
  38. package/src/api/action/enableAutoSaveAppState.js +73 -0
  39. package/src/api/action/getCurrentUserID.js +7 -0
  40. package/src/api/action/handleFriendRequest.js +57 -0
  41. package/src/api/action/logout.js +76 -0
  42. package/src/api/action/refreshFb_dtsg.js +48 -0
  43. package/src/api/action/setPostReaction.js +106 -0
  44. package/src/api/action/unfriend.js +54 -0
  45. package/src/api/http/httpGet.js +46 -0
  46. package/src/api/http/httpPost.js +52 -0
  47. package/src/api/http/postFormData.js +47 -0
  48. package/src/api/messaging/addUserToGroup.js +68 -0
  49. package/src/api/messaging/changeAdminStatus.js +126 -0
  50. package/src/api/messaging/changeArchivedStatus.js +55 -0
  51. package/src/api/messaging/changeBlockedStatus.js +48 -0
  52. package/src/api/messaging/changeGroupImage.js +91 -0
  53. package/src/api/messaging/changeNickname.js +70 -0
  54. package/src/api/messaging/changeThreadColor.js +79 -0
  55. package/src/api/messaging/changeThreadEmoji.js +111 -0
  56. package/src/api/messaging/createNewGroup.js +88 -0
  57. package/src/api/messaging/createPoll.js +46 -0
  58. package/src/api/messaging/createThemeAI.js +98 -0
  59. package/src/api/messaging/deleteMessage.js +136 -0
  60. package/src/api/messaging/deleteThread.js +56 -0
  61. package/src/api/messaging/editMessage.js +90 -0
  62. package/src/api/messaging/forwardAttachment.js +57 -0
  63. package/src/api/messaging/forwardMessage.js +134 -0
  64. package/src/api/messaging/getEmojiUrl.js +29 -0
  65. package/src/api/messaging/getFriendsList.js +82 -0
  66. package/src/api/messaging/getMessage.js +829 -0
  67. package/src/api/messaging/getThemePictures.js +62 -0
  68. package/src/api/messaging/handleMessageRequest.js +65 -0
  69. package/src/api/messaging/markAsDelivered.js +57 -0
  70. package/src/api/messaging/markAsRead.js +88 -0
  71. package/src/api/messaging/markAsReadAll.js +49 -0
  72. package/src/api/messaging/markAsSeen.js +61 -0
  73. package/src/api/messaging/muteThread.js +50 -0
  74. package/src/api/messaging/pinMessage.js +115 -0
  75. package/src/api/messaging/removeUserFromGroup.js +62 -0
  76. package/src/api/messaging/resolvePhotoUrl.js +43 -0
  77. package/src/api/messaging/scheduler.js +264 -0
  78. package/src/api/messaging/searchForThread.js +53 -0
  79. package/src/api/messaging/sendBroadcast.js +93 -0
  80. package/src/api/messaging/sendMessage.js +269 -0
  81. package/src/api/messaging/sendTypingIndicator.js +74 -0
  82. package/src/api/messaging/sessionGuard.js +208 -0
  83. package/src/api/messaging/setMessageReaction.js +95 -0
  84. package/src/api/messaging/setTitle.js +124 -0
  85. package/src/api/messaging/shareContact.js +49 -0
  86. package/src/api/messaging/threadColors.js +128 -0
  87. package/src/api/messaging/unsendMessage.js +81 -0
  88. package/src/api/messaging/uploadAttachment.js +523 -0
  89. package/src/api/socket/OldMessage.js +186 -0
  90. package/src/api/socket/core/connectMqtt.js +320 -0
  91. package/src/api/socket/core/emitAuth.js +103 -0
  92. package/src/api/socket/core/getSeqID.js +338 -0
  93. package/src/api/socket/core/getTaskResponseData.js +25 -0
  94. package/src/api/socket/core/parseDelta.js +387 -0
  95. package/src/api/socket/detail/buildStream.js +215 -0
  96. package/src/api/socket/detail/constants.js +28 -0
  97. package/src/api/socket/e2ee/crypto.js +173 -0
  98. package/src/api/socket/e2ee/e2ee/crypto.js +173 -0
  99. package/src/api/socket/e2ee/e2ee/index.js +421 -0
  100. package/src/api/socket/e2ee/e2ee/proto/ArmadilloApplication.proto +281 -0
  101. package/src/api/socket/e2ee/e2ee/proto/ArmadilloICDC.proto +14 -0
  102. package/src/api/socket/e2ee/e2ee/proto/ConsumerApplication.proto +232 -0
  103. package/src/api/socket/e2ee/e2ee/proto/MessageApplication.proto +82 -0
  104. package/src/api/socket/e2ee/e2ee/proto/MessageTransport.proto +77 -0
  105. package/src/api/socket/e2ee/e2ee/proto/WACommon.proto +66 -0
  106. package/src/api/socket/e2ee/e2ee/proto/WAMediaTransport.proto +176 -0
  107. package/src/api/socket/e2ee/e2ee/protocol.js +196 -0
  108. package/src/api/socket/e2ee/e2ee/ratchet.js +219 -0
  109. package/src/api/socket/e2ee/e2ee/store.js +182 -0
  110. package/src/api/socket/e2ee/e2ee/vendor/fb-e2ee.cjs +9162 -0
  111. package/src/api/socket/e2ee/e2ee/vendor/proto/ArmadilloApplication.proto +281 -0
  112. package/src/api/socket/e2ee/e2ee/vendor/proto/ArmadilloICDC.proto +14 -0
  113. package/src/api/socket/e2ee/e2ee/vendor/proto/ConsumerApplication.proto +232 -0
  114. package/src/api/socket/e2ee/e2ee/vendor/proto/MessageApplication.proto +82 -0
  115. package/src/api/socket/e2ee/e2ee/vendor/proto/MessageTransport.proto +77 -0
  116. package/src/api/socket/e2ee/e2ee/vendor/proto/WACommon.proto +66 -0
  117. package/src/api/socket/e2ee/e2ee/vendor/proto/WAMediaTransport.proto +176 -0
  118. package/src/api/socket/e2ee/index.js +437 -0
  119. package/src/api/socket/e2ee/proto/ArmadilloApplication.proto +281 -0
  120. package/src/api/socket/e2ee/proto/ArmadilloICDC.proto +14 -0
  121. package/src/api/socket/e2ee/proto/ConsumerApplication.proto +232 -0
  122. package/src/api/socket/e2ee/proto/MessageApplication.proto +82 -0
  123. package/src/api/socket/e2ee/proto/MessageTransport.proto +77 -0
  124. package/src/api/socket/e2ee/proto/WACommon.proto +66 -0
  125. package/src/api/socket/e2ee/proto/WAMediaTransport.proto +176 -0
  126. package/src/api/socket/e2ee/protocol.js +196 -0
  127. package/src/api/socket/e2ee/ratchet.js +219 -0
  128. package/src/api/socket/e2ee/store.js +182 -0
  129. package/src/api/socket/e2ee/vendor/fb-e2ee.cjs +9162 -0
  130. package/src/api/socket/e2ee/vendor/proto/ArmadilloApplication.proto +281 -0
  131. package/src/api/socket/e2ee/vendor/proto/ArmadilloICDC.proto +14 -0
  132. package/src/api/socket/e2ee/vendor/proto/ConsumerApplication.proto +232 -0
  133. package/src/api/socket/e2ee/vendor/proto/MessageApplication.proto +82 -0
  134. package/src/api/socket/e2ee/vendor/proto/MessageTransport.proto +77 -0
  135. package/src/api/socket/e2ee/vendor/proto/WACommon.proto +66 -0
  136. package/src/api/socket/e2ee/vendor/proto/WAMediaTransport.proto +176 -0
  137. package/src/api/socket/listenE2EE.js +75 -0
  138. package/src/api/socket/listenMqtt.js +551 -0
  139. package/src/api/socket/middleware/index.js +216 -0
  140. package/src/api/socket/sendMessage.js +309 -0
  141. package/src/api/socket/sendMessageMqtt.js +69 -0
  142. package/src/api/threads/getThreadHistory.js +664 -0
  143. package/src/api/threads/getThreadInfo.js +296 -0
  144. package/src/api/threads/getThreadList.js +293 -0
  145. package/src/api/threads/getThreadPictures.js +78 -0
  146. package/src/api/users/getUserID.js +65 -0
  147. package/src/api/users/getUserInfo.js +402 -0
  148. package/src/api/users/getUserInfoV2.js +911 -0
  149. package/src/app/MessengerBot.js +209 -0
  150. package/src/app/MessengerContext.js +32 -0
  151. package/src/app/createFcaClient.js +139 -0
  152. package/src/app/threadInfoRealtimeSync.js +284 -0
  153. package/src/core/sendReqMqtt.js +96 -0
  154. package/src/database/helpers.js +53 -0
  155. package/src/database/models/index.js +88 -0
  156. package/src/database/models/thread.js +50 -0
  157. package/src/database/models/user.js +46 -0
  158. package/src/database/threadData.js +94 -0
  159. package/src/database/userData.js +98 -0
  160. package/src/remote/remoteClient.js +123 -0
  161. package/src/utils/broadcast.js +51 -0
  162. package/src/utils/client.js +10 -0
  163. package/src/utils/clientIdentity.js +118 -0
  164. package/src/utils/constants.js +23 -0
  165. package/src/utils/cookies.js +68 -0
  166. package/src/utils/format/attachment.js +357 -0
  167. package/src/utils/format/cookie.js +9 -0
  168. package/src/utils/format/date.js +50 -0
  169. package/src/utils/format/decode.js +44 -0
  170. package/src/utils/format/delta.js +194 -0
  171. package/src/utils/format/ids.js +64 -0
  172. package/src/utils/format/index.js +64 -0
  173. package/src/utils/format/message.js +88 -0
  174. package/src/utils/format/presence.js +132 -0
  175. package/src/utils/format/readTyp.js +44 -0
  176. package/src/utils/format/thread.js +42 -0
  177. package/src/utils/format/utils.js +141 -0
  178. package/src/utils/headers.js +124 -0
  179. package/src/utils/logger.js +144 -0
  180. package/src/utils/loginParser/autoLogin.js +125 -0
  181. package/src/utils/loginParser/helpers.js +43 -0
  182. package/src/utils/loginParser/index.js +10 -0
  183. package/src/utils/loginParser/parseAndCheckLogin.js +220 -0
  184. package/src/utils/loginParser/textUtils.js +28 -0
  185. package/src/utils/request/client.js +26 -0
  186. package/src/utils/request/config.js +29 -0
  187. package/src/utils/request/defaults.js +46 -0
  188. package/src/utils/request/helpers.js +46 -0
  189. package/src/utils/request/index.js +17 -0
  190. package/src/utils/request/methods.js +163 -0
  191. package/src/utils/request/proxy.js +46 -0
  192. package/src/utils/request/retry.js +77 -0
  193. package/src/utils/request/sanitize.js +49 -0
  194. package/src/utils/utils.js +686 -0
  195. package/src/utils/versionCheck.js +47 -0
  196. package/src/vendor/fca-unofficial/index.js +11 -0
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ const { saveCookies, getAppState } = require("./cookies");
4
+ const { parseAndCheckLogin } = require("./loginParser");
5
+
6
+ module.exports = {
7
+ saveCookies,
8
+ getAppState,
9
+ parseAndCheckLogin
10
+ };
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ /**
3
+ * Centralized client-identity configuration.
4
+ *
5
+ * Problem this solves:
6
+ * Previously, User-Agent / sec-ch-ua / platform / arch / Accept-Language were
7
+ * hard-coded independently in several files (headers.js, connectMqtt.js,
8
+ * uploadAttachment.js, module/login.js, module/options.js) with DIFFERENT
9
+ * Chrome versions (121 / 125 / 139 / 143) and mismatched client hints.
10
+ * A single HTTP session that claims to be Chrome 121 in one request and
11
+ * Chrome 143 (with matching sec-ch-ua) in the next is internally
12
+ * inconsistent - it looks like two different browsers sharing one cookie
13
+ * jar, which is exactly the kind of implementation bug that produces
14
+ * "abnormal session" / forced logout behavior server-side.
15
+ *
16
+ * This module is the SINGLE source of truth for what a session claims to be.
17
+ * It does not rotate, randomize, or otherwise try to evade detection - it
18
+ * simply makes sure every subsystem (HTTP, MQTT/WebSocket, file upload)
19
+ * agrees on one coherent, stable identity for the lifetime of a session.
20
+ */
21
+
22
+ // One version pin used everywhere. Bump this in one place when needed.
23
+ const CHROME_VERSION = "139.0.0.0";
24
+ const CHROME_MAJOR = CHROME_VERSION.split(".")[0];
25
+
26
+ const DEFAULT_IDENTITY = Object.freeze({
27
+ userAgent: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${CHROME_VERSION} Safari/537.36`,
28
+ acceptLanguage: "en-US,en;q=0.9",
29
+ secChUa: `"Chromium";v="${CHROME_MAJOR}", "Not;A=Brand";v="24", "Google Chrome";v="${CHROME_MAJOR}"`,
30
+ secChUaMobile: "?0",
31
+ secChUaPlatform: '"Windows"',
32
+ secChUaArch: '"x86"',
33
+ secChUaBitness: '"64"',
34
+ secChUaFullVersionList: `"Chromium";v="${CHROME_VERSION}", "Not;A=Brand";v="24.0.0.0", "Google Chrome";v="${CHROME_VERSION}"`,
35
+ secChUaPlatformVersion: '"15.0.0"'
36
+ });
37
+
38
+ /**
39
+ * Derive a Chrome major version from a User-Agent string, if it looks like
40
+ * one of our own default UAs. Used so that if a caller supplies a custom
41
+ * Chrome UA via options, the client-hint headers we generate still line up
42
+ * with it instead of silently claiming a different version.
43
+ */
44
+ function extractChromeVersion(userAgent) {
45
+ if (typeof userAgent !== "string") return null;
46
+ const m = userAgent.match(/Chrome\/(\d+)\.(\d+)\.(\d+)\.(\d+)/);
47
+ if (!m) return null;
48
+ return { full: `${m[1]}.${m[2]}.${m[3]}.${m[4]}`, major: m[1] };
49
+ }
50
+
51
+ /**
52
+ * Build one internally-consistent identity object for a session.
53
+ * - No arguments: returns the stable default identity.
54
+ * - customUserAgent: if it's a recognizable Chrome UA, the sec-ch-ua/
55
+ * full-version-list are regenerated to match that exact version instead
56
+ * of contradicting it. Non-Chrome UAs get the UA respected as-is but no
57
+ * Chromium client hints are attached (since claiming Chromium hints next
58
+ * to a non-Chromium UA is itself a contradiction).
59
+ *
60
+ * This function is pure - it never mutates process-wide state and never
61
+ * changes its answer for the same input, so it is safe to call repeatedly
62
+ * for the same session without identity drift.
63
+ */
64
+ function getIdentity(customUserAgent) {
65
+ if (!customUserAgent || customUserAgent === DEFAULT_IDENTITY.userAgent) {
66
+ return DEFAULT_IDENTITY;
67
+ }
68
+
69
+ const parsed = extractChromeVersion(customUserAgent);
70
+ if (!parsed) {
71
+ // Unknown / non-Chrome UA supplied explicitly by the caller: respect it,
72
+ // but do not attach Chromium-specific client hints that would contradict it.
73
+ return Object.freeze({
74
+ userAgent: customUserAgent,
75
+ acceptLanguage: DEFAULT_IDENTITY.acceptLanguage,
76
+ secChUa: undefined,
77
+ secChUaMobile: undefined,
78
+ secChUaPlatform: undefined,
79
+ secChUaArch: undefined,
80
+ secChUaBitness: undefined,
81
+ secChUaFullVersionList: undefined,
82
+ secChUaPlatformVersion: undefined
83
+ });
84
+ }
85
+
86
+ return Object.freeze({
87
+ userAgent: customUserAgent,
88
+ acceptLanguage: DEFAULT_IDENTITY.acceptLanguage,
89
+ secChUa: `"Chromium";v="${parsed.major}", "Not;A=Brand";v="24", "Google Chrome";v="${parsed.major}"`,
90
+ secChUaMobile: "?0",
91
+ secChUaPlatform: DEFAULT_IDENTITY.secChUaPlatform,
92
+ secChUaArch: DEFAULT_IDENTITY.secChUaArch,
93
+ secChUaBitness: DEFAULT_IDENTITY.secChUaBitness,
94
+ secChUaFullVersionList: `"Chromium";v="${parsed.full}", "Not;A=Brand";v="24.0.0.0", "Google Chrome";v="${parsed.full}"`,
95
+ secChUaPlatformVersion: DEFAULT_IDENTITY.secChUaPlatformVersion
96
+ });
97
+ }
98
+
99
+ /**
100
+ * Resolve the identity that should be used for a given session context.
101
+ * Caches the resolved identity on the context object so it stays stable
102
+ * (does not get recomputed / drift) for the lifetime of that session, per
103
+ * requirement: "keep the identity stable for the lifetime of one
104
+ * authenticated session".
105
+ */
106
+ function getSessionIdentity(ctx) {
107
+ if (ctx && ctx._identity) return ctx._identity;
108
+ const identity = getIdentity(ctx && ctx.globalOptions && ctx.globalOptions.userAgent);
109
+ if (ctx) ctx._identity = identity;
110
+ return identity;
111
+ }
112
+
113
+ module.exports = {
114
+ CHROME_VERSION,
115
+ DEFAULT_IDENTITY,
116
+ getIdentity,
117
+ getSessionIdentity
118
+ };
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ const { getType } = require("./format");
3
+ const stream = require("stream");
4
+ function getFrom(html, a, b) {
5
+ const i = html.indexOf(a);
6
+ if (i < 0) return;
7
+ const start = i + a.length;
8
+ const j = html.indexOf(b, start);
9
+ return j < 0 ? undefined : html.slice(start, j);
10
+ }
11
+ function isReadableStream(obj) {
12
+ return (
13
+ obj instanceof stream.Stream &&
14
+ (getType(obj._read) === "Function" ||
15
+ getType(obj._read) === "AsyncFunction") &&
16
+ getType(obj._readableState) === "Object"
17
+ );
18
+ }
19
+
20
+ module.exports = {
21
+ getFrom,
22
+ isReadableStream
23
+ };
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ // Cookie helpers extracted from client.js
4
+
5
+ function saveCookies(jar) {
6
+ return res => {
7
+ try {
8
+ const setCookie = res?.headers?.["set-cookie"];
9
+ if (Array.isArray(setCookie) && setCookie.length) {
10
+ const url =
11
+ res?.request?.res?.responseUrl ||
12
+ (res?.config?.baseURL
13
+ ? new URL(res.config.url || "/", res.config.baseURL).toString()
14
+ : res?.config?.url || "https://www.facebook.com");
15
+ for (const c of setCookie) {
16
+ try {
17
+ jar.setCookieSync(c, url);
18
+ } catch {
19
+ // ignore per-cookie errors
20
+ }
21
+ }
22
+ }
23
+ } catch {
24
+ // ignore unexpected cookie parsing errors
25
+ }
26
+ return res;
27
+ };
28
+ }
29
+
30
+ function getAppState(jar) {
31
+ if (!jar || typeof jar.getCookiesSync !== "function") return [];
32
+ const urls = ["https://www.facebook.com"];
33
+ const all = urls.flatMap(u => {
34
+ try {
35
+ return jar.getCookiesSync(u) || [];
36
+ } catch {
37
+ return [];
38
+ }
39
+ });
40
+ const seen = new Set();
41
+ const out = [];
42
+ for (const c of all) {
43
+ const key = c.key || c.name;
44
+ if (!key) continue;
45
+ const id = key + "|" + (c.domain || "") + "|" + (c.path || "/");
46
+ if (seen.has(id)) continue;
47
+ seen.add(id);
48
+ out.push({
49
+ key,
50
+ value: c.value,
51
+ domain: c.domain || ".facebook.com",
52
+ path: c.path || "/",
53
+ hostOnly: !!c.hostOnly,
54
+ creation: c.creation || new Date(),
55
+ lastAccessed: c.lastAccessed || new Date(),
56
+ secure: !!c.secure,
57
+ httpOnly: !!c.httpOnly,
58
+ expires: c.expires && c.expires !== "Infinity" ? c.expires : "Infinity"
59
+ });
60
+ }
61
+ return out;
62
+ }
63
+
64
+ module.exports = {
65
+ saveCookies,
66
+ getAppState
67
+ };
68
+
@@ -0,0 +1,357 @@
1
+ "use strict";
2
+
3
+ var url = require("url");
4
+ const querystring = require("querystring");
5
+
6
+ function _formatAttachment(attachment1, attachment2) {
7
+ attachment2 = attachment2 || { id: "", image_data: {} };
8
+ attachment1 = attachment1.mercury ? attachment1.mercury : attachment1;
9
+ var blob = attachment1.blob_attachment;
10
+ var type =
11
+ blob && blob.__typename ? blob.__typename : attachment1.attach_type;
12
+ if (!type && attachment1.sticker_attachment) {
13
+ type = "StickerAttachment";
14
+ blob = attachment1.sticker_attachment;
15
+ } else if (!type && attachment1.extensible_attachment) {
16
+ if (
17
+ attachment1.extensible_attachment.story_attachment &&
18
+ attachment1.extensible_attachment.story_attachment.target &&
19
+ attachment1.extensible_attachment.story_attachment.target.__typename &&
20
+ attachment1.extensible_attachment.story_attachment.target.__typename ===
21
+ "MessageLocation"
22
+ )
23
+ type = "MessageLocation";
24
+ else type = "ExtensibleAttachment";
25
+
26
+ blob = attachment1.extensible_attachment;
27
+ }
28
+
29
+ if (blob && blob.real_metadata) {
30
+ const realMetadata = blob.real_metadata;
31
+ if (realMetadata.Src) {
32
+ attachment2.src = realMetadata.Src;
33
+ }
34
+ if (realMetadata.ThumbnailSrc) {
35
+ attachment2.thumbnailSrc = realMetadata.ThumbnailSrc;
36
+ }
37
+ }
38
+
39
+ switch (type) {
40
+ case "sticker":
41
+ return {
42
+ type: "sticker",
43
+ ID: attachment1.metadata.stickerID.toString(),
44
+ url: attachment1.url,
45
+ packID: attachment1.metadata.packID.toString(),
46
+ spriteUrl: attachment1.metadata.spriteURI,
47
+ spriteUrl2x: attachment1.metadata.spriteURI2x,
48
+ width: attachment1.metadata.width,
49
+ height: attachment1.metadata.height,
50
+ caption: attachment2.caption,
51
+ description: attachment2.description,
52
+ frameCount: attachment1.metadata.frameCount,
53
+ frameRate: attachment1.metadata.frameRate,
54
+ framesPerRow: attachment1.metadata.framesPerRow,
55
+ framesPerCol: attachment1.metadata.framesPerCol,
56
+ stickerID: attachment1.metadata.stickerID.toString(),
57
+ spriteURI: attachment1.metadata.spriteURI,
58
+ spriteURI2x: attachment1.metadata.spriteURI2x,
59
+ };
60
+ case "file":
61
+ return {
62
+ type: "file",
63
+ filename: attachment1.name,
64
+ ID: attachment2.id.toString(),
65
+ url: attachment1.url,
66
+ isMalicious: attachment2.is_malicious,
67
+ contentType: attachment2.mime_type,
68
+ name: attachment1.name,
69
+ mimeType: attachment2.mime_type,
70
+ fileSize: attachment2.file_size,
71
+ };
72
+ case "photo":
73
+ return {
74
+ type: "photo",
75
+ ID: attachment1.metadata.fbid.toString(),
76
+ filename: attachment1.fileName,
77
+ thumbnailUrl: attachment1.thumbnail_url,
78
+ previewUrl: attachment1.preview_url,
79
+ previewWidth: attachment1.preview_width,
80
+ previewHeight: attachment1.preview_height,
81
+ largePreviewUrl: attachment1.large_preview_url,
82
+ largePreviewWidth: attachment1.large_preview_width,
83
+ largePreviewHeight: attachment1.large_preview_height,
84
+ url: attachment1.metadata.url,
85
+ width: attachment1.metadata.dimensions.split(",")[0],
86
+ height: attachment1.metadata.dimensions.split(",")[1],
87
+ name: attachment1.fileName,
88
+ };
89
+ case "animated_image":
90
+ return {
91
+ type: "animated_image",
92
+ ID: attachment2.id.toString(),
93
+ filename: attachment2.filename,
94
+ previewUrl: attachment1.preview_url,
95
+ previewWidth: attachment1.preview_width,
96
+ previewHeight: attachment1.preview_height,
97
+ url: attachment2.image_data.url,
98
+ width: attachment2.image_data.width,
99
+ height: attachment2.image_data.height,
100
+ name: attachment1.name,
101
+ facebookUrl: attachment1.url,
102
+ thumbnailUrl: attachment1.thumbnail_url,
103
+ mimeType: attachment2.mime_type,
104
+ rawGifImage: attachment2.image_data.raw_gif_image,
105
+ rawWebpImage: attachment2.image_data.raw_webp_image,
106
+ animatedGifUrl: attachment2.image_data.animated_gif_url,
107
+ animatedGifPreviewUrl: attachment2.image_data.animated_gif_preview_url,
108
+ animatedWebpUrl: attachment2.image_data.animated_webp_url,
109
+ animatedWebpPreviewUrl:
110
+ attachment2.image_data.animated_webp_preview_url,
111
+ };
112
+ case "share":
113
+ return {
114
+ type: "share",
115
+ ID: attachment1.share.share_id.toString(),
116
+ url: attachment2.href,
117
+ title: attachment1.share.title,
118
+ description: attachment1.share.description,
119
+ source: attachment1.share.source,
120
+ image: attachment1.share.media.image,
121
+ width: attachment1.share.media.image_size.width,
122
+ height: attachment1.share.media.image_size.height,
123
+ playable: attachment1.share.media.playable,
124
+ duration: attachment1.share.media.duration,
125
+ subattachments: attachment1.share.subattachments,
126
+ properties: {},
127
+ animatedImageSize: attachment1.share.media.animated_image_size,
128
+ facebookUrl: attachment1.share.uri,
129
+ target: attachment1.share.target,
130
+ styleList: attachment1.share.style_list,
131
+ };
132
+ case "video":
133
+ return {
134
+ type: "video",
135
+ ID: attachment1.metadata.fbid.toString(),
136
+ filename: attachment1.name,
137
+ previewUrl: attachment1.preview_url,
138
+ previewWidth: attachment1.preview_width,
139
+ previewHeight: attachment1.preview_height,
140
+ url: attachment1.url,
141
+ width: attachment1.metadata.dimensions.width,
142
+ height: attachment1.metadata.dimensions.height,
143
+ duration: attachment1.metadata.duration,
144
+ videoType: "unknown",
145
+ thumbnailUrl: attachment1.thumbnail_url,
146
+ };
147
+ case "error":
148
+ return {
149
+ type: "error",
150
+ attachment1: attachment1,
151
+ attachment2: attachment2,
152
+ };
153
+ case "MessageImage":
154
+ return {
155
+ type: "photo",
156
+ ID: blob.legacy_attachment_id,
157
+ filename: blob.filename,
158
+ thumbnailUrl: blob.thumbnail.uri,
159
+ previewUrl: blob.preview.uri,
160
+ previewWidth: blob.preview.width,
161
+ previewHeight: blob.preview.height,
162
+ largePreviewUrl: blob.large_preview.uri,
163
+ largePreviewWidth: blob.large_preview.width,
164
+ largePreviewHeight: blob.large_preview.height,
165
+ url: blob.large_preview.uri,
166
+ width: blob.original_dimensions.x,
167
+ height: blob.original_dimensions.y,
168
+ name: blob.filename,
169
+ };
170
+ case "MessageAnimatedImage":
171
+ return {
172
+ type: "animated_image",
173
+ ID: blob.legacy_attachment_id,
174
+ filename: blob.filename,
175
+ previewUrl: blob.preview_image.uri,
176
+ previewWidth: blob.preview_image.width,
177
+ previewHeight: blob.preview_image.height,
178
+ url: blob.animated_image.uri,
179
+ width: blob.animated_image.width,
180
+ height: blob.animated_image.height,
181
+ thumbnailUrl: blob.preview_image.uri,
182
+ name: blob.filename,
183
+ facebookUrl: blob.animated_image.uri,
184
+ rawGifImage: blob.animated_image.uri,
185
+ animatedGifUrl: blob.animated_image.uri,
186
+ animatedGifPreviewUrl: blob.preview_image.uri,
187
+ animatedWebpUrl: blob.animated_image.uri,
188
+ animatedWebpPreviewUrl: blob.preview_image.uri,
189
+ };
190
+ case "MessageVideo":
191
+ return {
192
+ type: "video",
193
+ filename: blob.filename,
194
+ ID: blob.legacy_attachment_id,
195
+ previewUrl: blob.large_image.uri,
196
+ previewWidth: blob.large_image.width,
197
+ previewHeight: blob.large_image.height,
198
+ url: blob.playable_url,
199
+ width: blob.original_dimensions.x,
200
+ height: blob.original_dimensions.y,
201
+ duration: blob.playable_duration_in_ms,
202
+ videoType: blob.video_type.toLowerCase(),
203
+ thumbnailUrl: blob.large_image.uri,
204
+ };
205
+ case "MessageAudio":
206
+ return {
207
+ type: "audio",
208
+ filename: blob.filename,
209
+ ID: blob.url_shimhash,
210
+ audioType: blob.audio_type,
211
+ duration: blob.playable_duration_in_ms,
212
+ url: blob.playable_url,
213
+ isVoiceMail: blob.is_voicemail,
214
+ };
215
+ case "StickerAttachment":
216
+ return {
217
+ type: "sticker",
218
+ ID: blob.id,
219
+ url: blob.url,
220
+ packID: blob.pack ? blob.pack.id : null,
221
+ spriteUrl: blob.sprite_image,
222
+ spriteUrl2x: blob.sprite_image_2x,
223
+ width: blob.width,
224
+ height: blob.height,
225
+ caption: blob.label,
226
+ description: blob.label,
227
+ frameCount: blob.frame_count,
228
+ frameRate: blob.frame_rate,
229
+ framesPerRow: blob.frames_per_row,
230
+ framesPerCol: blob.frames_per_column,
231
+ stickerID: blob.id,
232
+ spriteURI: blob.sprite_image,
233
+ spriteURI2x: blob.sprite_image_2x,
234
+ };
235
+ case "MessageLocation": {
236
+ var urlAttach = blob.story_attachment.url;
237
+ var mediaAttach = blob.story_attachment.media;
238
+ var u = querystring.parse(url.parse(urlAttach).query).u;
239
+ var where1 = querystring.parse(url.parse(u).query).where1;
240
+ var address = where1.split(", ");
241
+ var latitude;
242
+ var longitude;
243
+ try {
244
+ latitude = Number.parseFloat(address[0]);
245
+ longitude = Number.parseFloat(address[1]);
246
+ } catch (err) {}
247
+ var imageUrl;
248
+ var width;
249
+ var height;
250
+ if (mediaAttach && mediaAttach.image) {
251
+ imageUrl = mediaAttach.image.uri;
252
+ width = mediaAttach.image.width;
253
+ height = mediaAttach.image.height;
254
+ }
255
+ return {
256
+ type: "location",
257
+ ID: blob.legacy_attachment_id,
258
+ latitude: latitude,
259
+ longitude: longitude,
260
+ image: imageUrl,
261
+ width: width,
262
+ height: height,
263
+ url: u || urlAttach,
264
+ address: where1,
265
+ facebookUrl: blob.story_attachment.url,
266
+ target: blob.story_attachment.target,
267
+ styleList: blob.story_attachment.style_list,
268
+ };
269
+ }
270
+ case "ExtensibleAttachment":
271
+ return {
272
+ type: "share",
273
+ ID: blob.legacy_attachment_id,
274
+ url: blob.story_attachment.url,
275
+ title: blob.story_attachment.title_with_entities.text,
276
+ description:
277
+ blob.story_attachment.description &&
278
+ blob.story_attachment.description.text,
279
+ source: blob.story_attachment.source
280
+ ? blob.story_attachment.source.text
281
+ : null,
282
+ image:
283
+ blob.story_attachment.media &&
284
+ blob.story_attachment.media.image &&
285
+ blob.story_attachment.media.image.uri,
286
+ width:
287
+ blob.story_attachment.media &&
288
+ blob.story_attachment.media.image &&
289
+ blob.story_attachment.media.image.width,
290
+ height:
291
+ blob.story_attachment.media &&
292
+ blob.story_attachment.media.image &&
293
+ blob.story_attachment.media.image.height,
294
+ playable:
295
+ blob.story_attachment.media &&
296
+ blob.story_attachment.media.is_playable,
297
+ duration:
298
+ blob.story_attachment.media &&
299
+ blob.story_attachment.media.playable_duration_in_ms,
300
+ playableUrl:
301
+ blob.story_attachment.media == null
302
+ ? null
303
+ : blob.story_attachment.media.playable_url,
304
+ subattachments: blob.story_attachment.subattachments,
305
+ properties: blob.story_attachment.properties.reduce(function (obj, cur) {
306
+ obj[cur.key] = cur.value.text;
307
+ return obj;
308
+ }, {}),
309
+ facebookUrl: blob.story_attachment.url,
310
+ target: blob.story_attachment.target,
311
+ styleList: blob.story_attachment.style_list,
312
+ };
313
+ case "MessageFile":
314
+ return {
315
+ type: "file",
316
+ filename: blob.filename,
317
+ ID: blob.message_file_fbid,
318
+ url: blob.url,
319
+ isMalicious: blob.is_malicious,
320
+ contentType: blob.content_type,
321
+ name: blob.filename,
322
+ mimeType: "",
323
+ fileSize: -1,
324
+ };
325
+ default:
326
+ throw new Error(
327
+ "unrecognized attach_file of type " +
328
+ type +
329
+ "`" +
330
+ JSON.stringify(attachment1, null, 4) +
331
+ " attachment2: " +
332
+ JSON.stringify(attachment2, null, 4) +
333
+ "`",
334
+ );
335
+ }
336
+ }
337
+
338
+ function formatAttachment(attachments, attachmentIds, attachmentMap, shareMap) {
339
+ attachmentMap = shareMap || attachmentMap;
340
+ return attachments
341
+ ? attachments.map(function (att, idx) {
342
+ if (
343
+ !attachmentMap ||
344
+ !attachmentIds ||
345
+ !attachmentMap[attachmentIds[idx]]
346
+ ) {
347
+ return _formatAttachment(att);
348
+ }
349
+ return _formatAttachment(att, attachmentMap[attachmentIds[idx]]);
350
+ })
351
+ : [];
352
+ }
353
+
354
+ module.exports = {
355
+ _formatAttachment,
356
+ formatAttachment,
357
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ function formatCookie(arr, urlBase) {
4
+ return arr[0] + "=" + arr[1] + "; Path=" + arr[3] + "; Domain=" + urlBase + ".com";
5
+ }
6
+
7
+ module.exports = {
8
+ formatCookie,
9
+ };
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ var NUM_TO_MONTH = [
4
+ "Jan",
5
+ "Feb",
6
+ "Mar",
7
+ "Apr",
8
+ "May",
9
+ "Jun",
10
+ "Jul",
11
+ "Aug",
12
+ "Sep",
13
+ "Oct",
14
+ "Nov",
15
+ "Dec",
16
+ ];
17
+ var NUM_TO_DAY = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
18
+
19
+ function formatDate(date) {
20
+ var d = date.getUTCDate();
21
+ d = d >= 10 ? d : "0" + d;
22
+ var h = date.getUTCHours();
23
+ h = h >= 10 ? h : "0" + h;
24
+ var m = date.getUTCMinutes();
25
+ m = m >= 10 ? m : "0" + m;
26
+ var s = date.getUTCSeconds();
27
+ s = s >= 10 ? s : "0" + s;
28
+ return (
29
+ NUM_TO_DAY[date.getUTCDay()] +
30
+ ", " +
31
+ d +
32
+ " " +
33
+ NUM_TO_MONTH[date.getUTCMonth()] +
34
+ " " +
35
+ date.getUTCFullYear() +
36
+ " " +
37
+ h +
38
+ ":" +
39
+ m +
40
+ ":" +
41
+ s +
42
+ " GMT"
43
+ );
44
+ }
45
+
46
+ module.exports = {
47
+ NUM_TO_MONTH,
48
+ NUM_TO_DAY,
49
+ formatDate,
50
+ };
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ function decodeClientPayload(payload) {
4
+ function Utf8ArrayToStr(array) {
5
+ var out, i, len, c;
6
+ var char2, char3;
7
+ out = "";
8
+ len = array.length;
9
+ i = 0;
10
+ while (i < len) {
11
+ c = array[i++];
12
+ switch (c >> 4) {
13
+ case 0:
14
+ case 1:
15
+ case 2:
16
+ case 3:
17
+ case 4:
18
+ case 5:
19
+ case 6:
20
+ case 7:
21
+ out += String.fromCharCode(c);
22
+ break;
23
+ case 12:
24
+ case 13:
25
+ char2 = array[i++];
26
+ out += String.fromCharCode(((c & 0x1f) << 6) | (char2 & 0x3f));
27
+ break;
28
+ case 14:
29
+ char2 = array[i++];
30
+ char3 = array[i++];
31
+ out += String.fromCharCode(
32
+ ((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0),
33
+ );
34
+ break;
35
+ }
36
+ }
37
+ return out;
38
+ }
39
+ return JSON.parse(Utf8ArrayToStr(payload));
40
+ }
41
+
42
+ module.exports = {
43
+ decodeClientPayload,
44
+ };