fca-smart-shankar 12.0.0 → 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.
- package/.replit +12 -3
- package/.upm/store.json +1 -0
- package/CHANGELOG.md +2 -0
- package/README.md +0 -1
- package/generated-icon.png +0 -0
- package/index.js +507 -437
- package/package.json +378 -42
- package/replit.nix +3 -1
- package/shankar-fca.json +4 -0
- package/src/addUserToGroup.js +3 -3
- package/src/changeAdminStatus.js +2 -2
- package/src/changeArchivedStatus.js +2 -2
- package/src/changeAvatar.js +8 -8
- package/src/changeAvatarV2.js +1 -1
- package/src/changeBio.js +4 -4
- package/src/changeBlockedStatus.js +2 -2
- package/src/changeCover.js +2 -2
- package/src/changeGroupImage.js +4 -4
- package/src/changeName.js +2 -2
- package/src/changeNickname.js +2 -2
- package/src/changeThreadColor.js +3 -3
- package/src/changeThreadEmoji.js +2 -2
- package/src/changeUsername.js +3 -3
- package/src/createCommentPost.js +5 -5
- package/src/createNewGroup.js +5 -5
- package/src/createPoll.js +2 -2
- package/src/createPost.js +6 -5
- package/src/deleteMessage.js +2 -2
- package/src/deleteThread.js +2 -2
- package/src/editMessage.js +30 -18
- package/src/follow.js +8 -8
- package/src/forwardAttachment.js +2 -2
- package/src/getAccess.js +2 -2
- package/src/getAvatarUser.js +2 -2
- package/src/getCurrentUserID.js +4 -4
- package/src/getFriendsList.js +3 -3
- package/src/getMessage.js +2 -2
- package/src/getThreadHistory.js +2 -2
- package/src/getThreadHistoryDeprecated.js +2 -2
- package/src/getThreadInfo.js +1 -1
- package/src/getThreadInfoDeprecated.js +2 -2
- package/src/getThreadList.js +3 -3
- package/src/getThreadListDeprecated.js +3 -3
- package/src/getThreadPictures.js +2 -2
- package/src/getUID.js +4 -4
- package/src/getUserID.js +3 -3
- package/src/getUserInfo.js +52 -18
- package/src/handleFriendRequest.js +5 -5
- package/src/handleMessageRequest.js +2 -2
- package/src/httpGet.js +3 -3
- package/src/httpPost.js +3 -3
- package/src/httpPostFormData.js +3 -3
- package/src/listenMqtt.js +648 -659
- package/src/listenNotification.js +1 -1
- package/src/logout.js +3 -3
- package/src/markAsDelivered.js +5 -2
- package/src/markAsRead.js +5 -2
- package/src/markAsReadAll.js +2 -2
- package/src/markAsSeen.js +2 -2
- package/src/muteThread.js +2 -2
- package/src/refreshFb_dtsg.js +3 -3
- package/src/removeUserFromGroup.js +2 -2
- package/src/resolvePhotoUrl.js +2 -2
- package/src/searchStickers.js +1 -1
- package/src/sendMessage.js +11 -8
- package/src/sendMessageMqtt.js +4 -4
- package/src/sendTypingIndicator.js +14 -5
- package/src/sendTypingIndicatorV2.js +1 -1
- package/src/setMessageReaction.js +3 -3
- package/src/setPostReaction.js +4 -4
- package/src/setProfileGuard.js +3 -3
- package/src/setStoryReaction.js +1 -1
- package/src/setTitle.js +3 -3
- package/src/shareContact.js +1 -1
- package/src/shareLink.js +1 -1
- package/src/stopListenMqtt.js +5 -2
- package/src/unfriend.js +2 -2
- package/src/unsendMessage.js +2 -2
- package/src/uploadAttachment.js +2 -2
- package/test/data/shareAttach.js +146 -0
- package/test/data/something.mov +0 -0
- package/test/data/test.png +0 -0
- package/test/data/test.txt +7 -0
- package/test/test-page.js +1 -1
- package/utils.js +564 -391
- package/.cache/nix/binary-cache-v6.sqlite +0 -0
- package/.cache/nix/binary-cache-v6.sqlite-journal +0 -0
- package/.cache/replit/env/latest +0 -125
- package/.cache/replit/env/latest.json +0 -1
- package/.cache/replit/modules/nix.res +0 -1
- package/.cache/replit/modules/nodejs-20.res +0 -1
- package/.cache/replit/modules/replit.res +0 -1
- package/.cache/replit/modules.stamp +0 -0
- package/.cache/replit/nix/env.json +0 -1
- package/.cache/typescript/5.6/node_modules/.package-lock.json +0 -171
- package/.cache/typescript/5.6/node_modules/@types/bluebird/LICENSE +0 -21
- package/.cache/typescript/5.6/node_modules/@types/bluebird/README.md +0 -15
- package/.cache/typescript/5.6/node_modules/@types/bluebird/index.d.ts +0 -1365
- package/.cache/typescript/5.6/node_modules/@types/bluebird/package.json +0 -25
- package/.cache/typescript/5.6/node_modules/@types/caseless/LICENSE +0 -21
- package/.cache/typescript/5.6/node_modules/@types/caseless/README.md +0 -48
- package/.cache/typescript/5.6/node_modules/@types/caseless/index.d.ts +0 -29
- package/.cache/typescript/5.6/node_modules/@types/caseless/package.json +0 -35
- package/.cache/typescript/5.6/node_modules/@types/cheerio/LICENSE +0 -21
- package/.cache/typescript/5.6/node_modules/@types/cheerio/README.md +0 -15
- package/.cache/typescript/5.6/node_modules/@types/cheerio/index.d.ts +0 -318
- package/.cache/typescript/5.6/node_modules/@types/cheerio/package.json +0 -71
- package/.cache/typescript/5.6/node_modules/@types/mocha/LICENSE +0 -21
- package/.cache/typescript/5.6/node_modules/@types/mocha/README.md +0 -15
- package/.cache/typescript/5.6/node_modules/@types/mocha/index.d.ts +0 -2929
- package/.cache/typescript/5.6/node_modules/@types/mocha/package.json +0 -56
- package/.cache/typescript/5.6/node_modules/@types/node/LICENSE +0 -21
- package/.cache/typescript/5.6/node_modules/@types/node/README.md +0 -15
- package/.cache/typescript/5.6/node_modules/@types/node/assert/strict.d.ts +0 -8
- package/.cache/typescript/5.6/node_modules/@types/node/assert.d.ts +0 -1040
- package/.cache/typescript/5.6/node_modules/@types/node/async_hooks.d.ts +0 -541
- package/.cache/typescript/5.6/node_modules/@types/node/buffer.buffer.d.ts +0 -385
- package/.cache/typescript/5.6/node_modules/@types/node/buffer.d.ts +0 -1933
- package/.cache/typescript/5.6/node_modules/@types/node/child_process.d.ts +0 -1549
- package/.cache/typescript/5.6/node_modules/@types/node/cluster.d.ts +0 -579
- package/.cache/typescript/5.6/node_modules/@types/node/compatibility/disposable.d.ts +0 -16
- package/.cache/typescript/5.6/node_modules/@types/node/compatibility/index.d.ts +0 -9
- package/.cache/typescript/5.6/node_modules/@types/node/compatibility/indexable.d.ts +0 -23
- package/.cache/typescript/5.6/node_modules/@types/node/compatibility/iterators.d.ts +0 -21
- package/.cache/typescript/5.6/node_modules/@types/node/console.d.ts +0 -452
- package/.cache/typescript/5.6/node_modules/@types/node/constants.d.ts +0 -19
- package/.cache/typescript/5.6/node_modules/@types/node/crypto.d.ts +0 -4475
- package/.cache/typescript/5.6/node_modules/@types/node/dgram.d.ts +0 -596
- package/.cache/typescript/5.6/node_modules/@types/node/diagnostics_channel.d.ts +0 -554
- package/.cache/typescript/5.6/node_modules/@types/node/dns/promises.d.ts +0 -476
- package/.cache/typescript/5.6/node_modules/@types/node/dns.d.ts +0 -865
- package/.cache/typescript/5.6/node_modules/@types/node/dom-events.d.ts +0 -124
- package/.cache/typescript/5.6/node_modules/@types/node/domain.d.ts +0 -170
- package/.cache/typescript/5.6/node_modules/@types/node/events.d.ts +0 -931
- package/.cache/typescript/5.6/node_modules/@types/node/fs/promises.d.ts +0 -1275
- package/.cache/typescript/5.6/node_modules/@types/node/fs.d.ts +0 -4396
- package/.cache/typescript/5.6/node_modules/@types/node/globals.d.ts +0 -566
- package/.cache/typescript/5.6/node_modules/@types/node/globals.typedarray.d.ts +0 -21
- package/.cache/typescript/5.6/node_modules/@types/node/http.d.ts +0 -1958
- package/.cache/typescript/5.6/node_modules/@types/node/http2.d.ts +0 -2558
- package/.cache/typescript/5.6/node_modules/@types/node/https.d.ts +0 -543
- package/.cache/typescript/5.6/node_modules/@types/node/index.d.ts +0 -92
- package/.cache/typescript/5.6/node_modules/@types/node/inspector.d.ts +0 -3966
- package/.cache/typescript/5.6/node_modules/@types/node/module.d.ts +0 -402
- package/.cache/typescript/5.6/node_modules/@types/node/net.d.ts +0 -1001
- package/.cache/typescript/5.6/node_modules/@types/node/os.d.ts +0 -495
- package/.cache/typescript/5.6/node_modules/@types/node/package.json +0 -220
- package/.cache/typescript/5.6/node_modules/@types/node/path.d.ts +0 -200
- package/.cache/typescript/5.6/node_modules/@types/node/perf_hooks.d.ts +0 -965
- package/.cache/typescript/5.6/node_modules/@types/node/process.d.ts +0 -1963
- package/.cache/typescript/5.6/node_modules/@types/node/punycode.d.ts +0 -117
- package/.cache/typescript/5.6/node_modules/@types/node/querystring.d.ts +0 -153
- package/.cache/typescript/5.6/node_modules/@types/node/readline/promises.d.ts +0 -162
- package/.cache/typescript/5.6/node_modules/@types/node/readline.d.ts +0 -589
- package/.cache/typescript/5.6/node_modules/@types/node/repl.d.ts +0 -430
- package/.cache/typescript/5.6/node_modules/@types/node/sea.d.ts +0 -153
- package/.cache/typescript/5.6/node_modules/@types/node/sqlite.d.ts +0 -213
- package/.cache/typescript/5.6/node_modules/@types/node/stream/consumers.d.ts +0 -12
- package/.cache/typescript/5.6/node_modules/@types/node/stream/promises.d.ts +0 -90
- package/.cache/typescript/5.6/node_modules/@types/node/stream/web.d.ts +0 -609
- package/.cache/typescript/5.6/node_modules/@types/node/stream.d.ts +0 -1726
- package/.cache/typescript/5.6/node_modules/@types/node/string_decoder.d.ts +0 -67
- package/.cache/typescript/5.6/node_modules/@types/node/test.d.ts +0 -2248
- package/.cache/typescript/5.6/node_modules/@types/node/timers/promises.d.ts +0 -97
- package/.cache/typescript/5.6/node_modules/@types/node/timers.d.ts +0 -240
- package/.cache/typescript/5.6/node_modules/@types/node/tls.d.ts +0 -1226
- package/.cache/typescript/5.6/node_modules/@types/node/trace_events.d.ts +0 -197
- package/.cache/typescript/5.6/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +0 -385
- package/.cache/typescript/5.6/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +0 -19
- package/.cache/typescript/5.6/node_modules/@types/node/ts5.6/index.d.ts +0 -92
- package/.cache/typescript/5.6/node_modules/@types/node/tty.d.ts +0 -208
- package/.cache/typescript/5.6/node_modules/@types/node/url.d.ts +0 -972
- package/.cache/typescript/5.6/node_modules/@types/node/util.d.ts +0 -2371
- package/.cache/typescript/5.6/node_modules/@types/node/v8.d.ts +0 -808
- package/.cache/typescript/5.6/node_modules/@types/node/vm.d.ts +0 -976
- package/.cache/typescript/5.6/node_modules/@types/node/wasi.d.ts +0 -181
- package/.cache/typescript/5.6/node_modules/@types/node/worker_threads.d.ts +0 -745
- package/.cache/typescript/5.6/node_modules/@types/node/zlib.d.ts +0 -539
- package/.cache/typescript/5.6/node_modules/@types/request/LICENSE +0 -21
- package/.cache/typescript/5.6/node_modules/@types/request/README.md +0 -15
- package/.cache/typescript/5.6/node_modules/@types/request/index.d.ts +0 -395
- package/.cache/typescript/5.6/node_modules/@types/request/package.json +0 -70
- package/.cache/typescript/5.6/node_modules/@types/tough-cookie/LICENSE +0 -21
- package/.cache/typescript/5.6/node_modules/@types/tough-cookie/README.md +0 -15
- package/.cache/typescript/5.6/node_modules/@types/tough-cookie/index.d.ts +0 -321
- package/.cache/typescript/5.6/node_modules/@types/tough-cookie/package.json +0 -35
- package/.cache/typescript/5.6/node_modules/asynckit/LICENSE +0 -21
- package/.cache/typescript/5.6/node_modules/asynckit/README.md +0 -233
- package/.cache/typescript/5.6/node_modules/asynckit/bench.js +0 -76
- package/.cache/typescript/5.6/node_modules/asynckit/index.js +0 -6
- package/.cache/typescript/5.6/node_modules/asynckit/lib/abort.js +0 -29
- package/.cache/typescript/5.6/node_modules/asynckit/lib/async.js +0 -34
- package/.cache/typescript/5.6/node_modules/asynckit/lib/defer.js +0 -26
- package/.cache/typescript/5.6/node_modules/asynckit/lib/iterate.js +0 -75
- package/.cache/typescript/5.6/node_modules/asynckit/lib/readable_asynckit.js +0 -91
- package/.cache/typescript/5.6/node_modules/asynckit/lib/readable_parallel.js +0 -25
- package/.cache/typescript/5.6/node_modules/asynckit/lib/readable_serial.js +0 -25
- package/.cache/typescript/5.6/node_modules/asynckit/lib/readable_serial_ordered.js +0 -29
- package/.cache/typescript/5.6/node_modules/asynckit/lib/state.js +0 -37
- package/.cache/typescript/5.6/node_modules/asynckit/lib/streamify.js +0 -141
- package/.cache/typescript/5.6/node_modules/asynckit/lib/terminator.js +0 -29
- package/.cache/typescript/5.6/node_modules/asynckit/package.json +0 -63
- package/.cache/typescript/5.6/node_modules/asynckit/parallel.js +0 -43
- package/.cache/typescript/5.6/node_modules/asynckit/serial.js +0 -17
- package/.cache/typescript/5.6/node_modules/asynckit/serialOrdered.js +0 -75
- package/.cache/typescript/5.6/node_modules/asynckit/stream.js +0 -21
- package/.cache/typescript/5.6/node_modules/combined-stream/License +0 -19
- package/.cache/typescript/5.6/node_modules/combined-stream/Readme.md +0 -138
- package/.cache/typescript/5.6/node_modules/combined-stream/lib/combined_stream.js +0 -208
- package/.cache/typescript/5.6/node_modules/combined-stream/package.json +0 -25
- package/.cache/typescript/5.6/node_modules/combined-stream/yarn.lock +0 -17
- package/.cache/typescript/5.6/node_modules/delayed-stream/License +0 -19
- package/.cache/typescript/5.6/node_modules/delayed-stream/Makefile +0 -7
- package/.cache/typescript/5.6/node_modules/delayed-stream/Readme.md +0 -141
- package/.cache/typescript/5.6/node_modules/delayed-stream/lib/delayed_stream.js +0 -107
- package/.cache/typescript/5.6/node_modules/delayed-stream/package.json +0 -27
- package/.cache/typescript/5.6/node_modules/form-data/License +0 -19
- package/.cache/typescript/5.6/node_modules/form-data/Readme.md +0 -350
- package/.cache/typescript/5.6/node_modules/form-data/index.d.ts +0 -51
- package/.cache/typescript/5.6/node_modules/form-data/lib/browser.js +0 -2
- package/.cache/typescript/5.6/node_modules/form-data/lib/form_data.js +0 -484
- package/.cache/typescript/5.6/node_modules/form-data/lib/populate.js +0 -10
- package/.cache/typescript/5.6/node_modules/form-data/package.json +0 -72
- package/.cache/typescript/5.6/node_modules/mime-db/HISTORY.md +0 -507
- package/.cache/typescript/5.6/node_modules/mime-db/LICENSE +0 -23
- package/.cache/typescript/5.6/node_modules/mime-db/README.md +0 -100
- package/.cache/typescript/5.6/node_modules/mime-db/db.json +0 -8519
- package/.cache/typescript/5.6/node_modules/mime-db/index.js +0 -12
- package/.cache/typescript/5.6/node_modules/mime-db/package.json +0 -60
- package/.cache/typescript/5.6/node_modules/mime-types/HISTORY.md +0 -397
- package/.cache/typescript/5.6/node_modules/mime-types/LICENSE +0 -23
- package/.cache/typescript/5.6/node_modules/mime-types/README.md +0 -113
- package/.cache/typescript/5.6/node_modules/mime-types/index.js +0 -188
- package/.cache/typescript/5.6/node_modules/mime-types/package.json +0 -44
- package/.cache/typescript/5.6/node_modules/safe-buffer/LICENSE +0 -21
- package/.cache/typescript/5.6/node_modules/safe-buffer/README.md +0 -584
- package/.cache/typescript/5.6/node_modules/safe-buffer/index.d.ts +0 -187
- package/.cache/typescript/5.6/node_modules/safe-buffer/index.js +0 -65
- package/.cache/typescript/5.6/node_modules/safe-buffer/package.json +0 -51
- package/.cache/typescript/5.6/node_modules/types-registry/README.md +0 -2
- package/.cache/typescript/5.6/node_modules/types-registry/index.json +0 -1
- package/.cache/typescript/5.6/node_modules/types-registry/package.json +0 -20
- package/.cache/typescript/5.6/node_modules/undici-types/LICENSE +0 -21
- package/.cache/typescript/5.6/node_modules/undici-types/README.md +0 -6
- package/.cache/typescript/5.6/node_modules/undici-types/agent.d.ts +0 -31
- package/.cache/typescript/5.6/node_modules/undici-types/api.d.ts +0 -43
- package/.cache/typescript/5.6/node_modules/undici-types/balanced-pool.d.ts +0 -29
- package/.cache/typescript/5.6/node_modules/undici-types/cache.d.ts +0 -36
- package/.cache/typescript/5.6/node_modules/undici-types/client.d.ts +0 -108
- package/.cache/typescript/5.6/node_modules/undici-types/connector.d.ts +0 -34
- package/.cache/typescript/5.6/node_modules/undici-types/content-type.d.ts +0 -21
- package/.cache/typescript/5.6/node_modules/undici-types/cookies.d.ts +0 -28
- package/.cache/typescript/5.6/node_modules/undici-types/diagnostics-channel.d.ts +0 -66
- package/.cache/typescript/5.6/node_modules/undici-types/dispatcher.d.ts +0 -255
- package/.cache/typescript/5.6/node_modules/undici-types/env-http-proxy-agent.d.ts +0 -21
- package/.cache/typescript/5.6/node_modules/undici-types/errors.d.ts +0 -149
- package/.cache/typescript/5.6/node_modules/undici-types/eventsource.d.ts +0 -61
- package/.cache/typescript/5.6/node_modules/undici-types/fetch.d.ts +0 -209
- package/.cache/typescript/5.6/node_modules/undici-types/file.d.ts +0 -39
- package/.cache/typescript/5.6/node_modules/undici-types/filereader.d.ts +0 -54
- package/.cache/typescript/5.6/node_modules/undici-types/formdata.d.ts +0 -108
- package/.cache/typescript/5.6/node_modules/undici-types/global-dispatcher.d.ts +0 -9
- package/.cache/typescript/5.6/node_modules/undici-types/global-origin.d.ts +0 -7
- package/.cache/typescript/5.6/node_modules/undici-types/handlers.d.ts +0 -15
- package/.cache/typescript/5.6/node_modules/undici-types/header.d.ts +0 -4
- package/.cache/typescript/5.6/node_modules/undici-types/index.d.ts +0 -71
- package/.cache/typescript/5.6/node_modules/undici-types/interceptors.d.ts +0 -17
- package/.cache/typescript/5.6/node_modules/undici-types/mock-agent.d.ts +0 -50
- package/.cache/typescript/5.6/node_modules/undici-types/mock-client.d.ts +0 -25
- package/.cache/typescript/5.6/node_modules/undici-types/mock-errors.d.ts +0 -12
- package/.cache/typescript/5.6/node_modules/undici-types/mock-interceptor.d.ts +0 -93
- package/.cache/typescript/5.6/node_modules/undici-types/mock-pool.d.ts +0 -25
- package/.cache/typescript/5.6/node_modules/undici-types/package.json +0 -55
- package/.cache/typescript/5.6/node_modules/undici-types/patch.d.ts +0 -33
- package/.cache/typescript/5.6/node_modules/undici-types/pool-stats.d.ts +0 -19
- package/.cache/typescript/5.6/node_modules/undici-types/pool.d.ts +0 -39
- package/.cache/typescript/5.6/node_modules/undici-types/proxy-agent.d.ts +0 -28
- package/.cache/typescript/5.6/node_modules/undici-types/readable.d.ts +0 -60
- package/.cache/typescript/5.6/node_modules/undici-types/retry-agent.d.ts +0 -8
- package/.cache/typescript/5.6/node_modules/undici-types/retry-handler.d.ts +0 -116
- package/.cache/typescript/5.6/node_modules/undici-types/util.d.ts +0 -18
- package/.cache/typescript/5.6/node_modules/undici-types/webidl.d.ts +0 -222
- package/.cache/typescript/5.6/node_modules/undici-types/websocket.d.ts +0 -150
- package/.cache/typescript/5.6/package-lock.json +0 -183
- package/.cache/typescript/5.6/package.json +0 -1
package/utils.js
CHANGED
@@ -1,112 +1,185 @@
|
|
1
|
-
|
2
|
-
/* eslint-disable no-prototype-builtins */
|
1
|
+
/* eslint-disable no-prototype-builtins */
|
3
2
|
"use strict";
|
4
3
|
|
5
|
-
let request = require("request").defaults({ jar: true });
|
4
|
+
let request = promisifyPromise(require("request").defaults({ jar: true, proxy: process.env.FB_PROXY }));
|
6
5
|
const stream = require("stream");
|
6
|
+
const log = require("npmlog");
|
7
7
|
const querystring = require("querystring");
|
8
8
|
const url = require("url");
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
class CustomError extends Error {
|
11
|
+
constructor(obj) {
|
12
|
+
if (typeof obj === 'string')
|
13
|
+
obj = { message: obj };
|
14
|
+
if (typeof obj !== 'object' || obj === null)
|
15
|
+
throw new TypeError('Object required');
|
16
|
+
obj.message ? super(obj.message) : super();
|
17
|
+
Object.assign(this, obj);
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
function callbackToPromise(func) {
|
22
|
+
return function (...args) {
|
23
|
+
return new Promise((resolve, reject) => {
|
24
|
+
func(...args, (err, data) => {
|
25
|
+
if (err)
|
26
|
+
reject(err);
|
27
|
+
else
|
28
|
+
resolve(data);
|
29
|
+
});
|
30
|
+
});
|
31
|
+
};
|
32
|
+
}
|
33
|
+
|
34
|
+
function isHasCallback(func) {
|
35
|
+
if (typeof func !== "function")
|
36
|
+
return false;
|
37
|
+
return func.toString().split("\n")[0].match(/(callback|cb)\s*\)/) !== null;
|
38
|
+
}
|
39
|
+
|
40
|
+
// replace for bluebird.promisify (but this only applies best to the `request` package)
|
41
|
+
function promisifyPromise(promise) {
|
42
|
+
const keys = Object.keys(promise);
|
43
|
+
let promise_;
|
44
|
+
if (
|
45
|
+
typeof promise === "function"
|
46
|
+
&& isHasCallback(promise)
|
47
|
+
)
|
48
|
+
promise_ = callbackToPromise(promise);
|
49
|
+
else
|
50
|
+
promise_ = promise;
|
51
|
+
|
52
|
+
for (const key of keys) {
|
53
|
+
if (!promise[key]?.toString)
|
54
|
+
continue;
|
55
|
+
|
56
|
+
if (
|
57
|
+
typeof promise[key] === "function"
|
58
|
+
&& isHasCallback(promise[key])
|
59
|
+
) {
|
60
|
+
promise_[key] = callbackToPromise(promise[key]);
|
61
|
+
}
|
62
|
+
else {
|
63
|
+
promise_[key] = promise[key];
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
return promise_;
|
68
|
+
}
|
69
|
+
|
70
|
+
// replace for bluebird.delay
|
71
|
+
function delay(ms) {
|
72
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
73
|
+
}
|
74
|
+
|
75
|
+
// replace for bluebird.try
|
76
|
+
function tryPromise(tryFunc) {
|
77
|
+
return new Promise((resolve, reject) => {
|
78
|
+
try {
|
79
|
+
resolve(tryFunc());
|
80
|
+
} catch (error) {
|
81
|
+
reject(error);
|
82
|
+
}
|
83
|
+
});
|
84
|
+
}
|
85
|
+
|
86
|
+
function setProxy(url) {
|
87
|
+
if (typeof url == "undefined")
|
88
|
+
return request = promisifyPromise(require("request").defaults({
|
89
|
+
jar: true
|
90
|
+
}));
|
91
|
+
return request = promisifyPromise(require("request").defaults({
|
92
|
+
jar: true,
|
93
|
+
proxy: url
|
94
|
+
}));
|
16
95
|
}
|
17
96
|
|
18
97
|
function getHeaders(url, options, ctx, customHeader) {
|
19
|
-
|
98
|
+
const headers = {
|
20
99
|
"Content-Type": "application/x-www-form-urlencoded",
|
21
100
|
Referer: "https://www.facebook.com/",
|
22
|
-
Host:
|
101
|
+
Host: url.replace("https://", "").split("/")[0],
|
23
102
|
Origin: "https://www.facebook.com",
|
24
103
|
"User-Agent": options.userAgent,
|
25
104
|
Connection: "keep-alive",
|
26
|
-
"
|
27
|
-
'Sec-Fetch-User': '?1'
|
105
|
+
"sec-fetch-site": "same-origin"
|
28
106
|
};
|
29
107
|
if (customHeader) {
|
30
108
|
Object.assign(headers, customHeader);
|
31
|
-
if (customHeader.noRef)
|
32
|
-
delete headers.Referer;
|
33
109
|
}
|
34
|
-
if (ctx && ctx.region)
|
35
|
-
|
110
|
+
if (ctx && ctx.region) {
|
111
|
+
headers["X-MSGR-Region"] = ctx.region;
|
112
|
+
}
|
36
113
|
|
37
114
|
return headers;
|
38
115
|
}
|
39
116
|
|
40
117
|
function isReadableStream(obj) {
|
41
|
-
return
|
118
|
+
return (
|
119
|
+
obj instanceof stream.Stream &&
|
120
|
+
(getType(obj._read) === "Function" ||
|
121
|
+
getType(obj._read) === "AsyncFunction") &&
|
122
|
+
getType(obj._readableState) === "Object"
|
123
|
+
);
|
42
124
|
}
|
43
125
|
|
44
|
-
function get(url, jar, qs, options, ctx
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
qs[prop] = JSON.stringify(qs[prop]);
|
53
|
-
}
|
54
|
-
var op = {
|
55
|
-
headers: getHeaders(url, options, ctx, customHeader),
|
56
|
-
timeout: 60000,
|
57
|
-
qs,
|
58
|
-
jar,
|
59
|
-
gzip: !0
|
126
|
+
function get(url, jar, qs, options, ctx) {
|
127
|
+
// I'm still confused about this
|
128
|
+
if (getType(qs) === "Object") {
|
129
|
+
for (const prop in qs) {
|
130
|
+
if (qs.hasOwnProperty(prop) && getType(qs[prop]) === "Object") {
|
131
|
+
qs[prop] = JSON.stringify(qs[prop]);
|
132
|
+
}
|
133
|
+
}
|
60
134
|
}
|
135
|
+
const op = {
|
136
|
+
headers: getHeaders(url, options, ctx),
|
137
|
+
timeout: 60000,
|
138
|
+
qs: qs,
|
139
|
+
url: url,
|
140
|
+
method: "GET",
|
141
|
+
jar: jar,
|
142
|
+
gzip: true
|
143
|
+
};
|
61
144
|
|
62
|
-
|
63
|
-
|
64
|
-
|
145
|
+
return request(op).then(function (res) {
|
146
|
+
return Array.isArray(res) ? res[0] : res;
|
147
|
+
});
|
65
148
|
}
|
66
149
|
|
67
150
|
function post(url, jar, form, options, ctx, customHeader) {
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
jar,
|
78
|
-
gzip: !0
|
79
|
-
}
|
80
|
-
|
81
|
-
request.post(url, op, callback);
|
151
|
+
const op = {
|
152
|
+
headers: getHeaders(url, options, ctx, customHeader),
|
153
|
+
timeout: 60000,
|
154
|
+
url: url,
|
155
|
+
method: "POST",
|
156
|
+
form: form,
|
157
|
+
jar: jar,
|
158
|
+
gzip: true
|
159
|
+
};
|
82
160
|
|
83
|
-
return
|
161
|
+
return request(op).then(function (res) {
|
162
|
+
return Array.isArray(res) ? res[0] : res;
|
163
|
+
});
|
84
164
|
}
|
85
165
|
|
86
166
|
function postFormData(url, jar, form, qs, options, ctx) {
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
if (getType(qs) == "Object")
|
92
|
-
for (let prop in qs) {
|
93
|
-
if (getType(qs[prop]) == 'Object')
|
94
|
-
qs[prop] = JSON.stringify(qs[prop]);
|
95
|
-
}
|
96
|
-
var op = {
|
97
|
-
headers: getHeaders(url, options, ctx, {
|
98
|
-
'Content-Type': 'multipart/form-data'
|
99
|
-
}),
|
167
|
+
const headers = getHeaders(url, options, ctx);
|
168
|
+
headers["Content-Type"] = "multipart/form-data";
|
169
|
+
const op = {
|
170
|
+
headers: headers,
|
100
171
|
timeout: 60000,
|
172
|
+
url: url,
|
173
|
+
method: "POST",
|
101
174
|
formData: form,
|
102
|
-
qs,
|
103
|
-
jar,
|
104
|
-
gzip:
|
105
|
-
}
|
106
|
-
|
107
|
-
request.post(url, op, callback);
|
175
|
+
qs: qs,
|
176
|
+
jar: jar,
|
177
|
+
gzip: true
|
178
|
+
};
|
108
179
|
|
109
|
-
return
|
180
|
+
return request(op).then(function (res) {
|
181
|
+
return Array.isArray(res) ? res[0] : res;
|
182
|
+
});
|
110
183
|
}
|
111
184
|
|
112
185
|
function padZeros(val, len) {
|
@@ -709,57 +782,61 @@ function _formatAttachment(attachment1, attachment2) {
|
|
709
782
|
}
|
710
783
|
|
711
784
|
function formatAttachment(attachments, attachmentIds, attachmentMap, shareMap) {
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
785
|
+
attachmentMap = shareMap || attachmentMap;
|
786
|
+
return attachments
|
787
|
+
? attachments.map(function (val, i) {
|
788
|
+
if (
|
789
|
+
!attachmentMap ||
|
790
|
+
!attachmentIds ||
|
791
|
+
!attachmentMap[attachmentIds[i]]
|
792
|
+
) {
|
793
|
+
return _formatAttachment(val);
|
794
|
+
}
|
795
|
+
return _formatAttachment(val, attachmentMap[attachmentIds[i]]);
|
796
|
+
})
|
797
|
+
: [];
|
725
798
|
}
|
726
799
|
|
727
800
|
function formatDeltaMessage(m) {
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
801
|
+
var md = m.delta.messageMetadata;
|
802
|
+
|
803
|
+
var mdata =
|
804
|
+
m.delta.data === undefined
|
805
|
+
? []
|
806
|
+
: m.delta.data.prng === undefined
|
807
|
+
? []
|
808
|
+
: JSON.parse(m.delta.data.prng);
|
809
|
+
var m_id = mdata.map(u => u.i);
|
810
|
+
var m_offset = mdata.map(u => u.o);
|
811
|
+
var m_length = mdata.map(u => u.l);
|
812
|
+
var mentions = {};
|
813
|
+
var body = m.delta.body || "";
|
814
|
+
var args = body == "" ? [] : body.trim().split(/\s+/);
|
815
|
+
for (var i = 0; i < m_id.length; i++) {
|
816
|
+
mentions[m_id[i]] = m.delta.body.substring(
|
817
|
+
m_offset[i],
|
818
|
+
m_offset[i] + m_length[i]
|
819
|
+
);
|
820
|
+
}
|
746
821
|
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
822
|
+
return {
|
823
|
+
type: "message",
|
824
|
+
senderID: formatID(md.actorFbId.toString()),
|
825
|
+
threadID: formatID(
|
826
|
+
(md.threadKey.threadFbId || md.threadKey.otherUserFbId).toString()
|
827
|
+
),
|
828
|
+
args: args,
|
829
|
+
body: body,
|
830
|
+
messageID: md.messageId,
|
831
|
+
attachments: (m.delta.attachments || []).map(v => _formatAttachment(v)),
|
832
|
+
mentions: mentions,
|
833
|
+
timestamp: md.timestamp,
|
834
|
+
isGroup: !!md.threadKey.threadFbId,
|
835
|
+
participantIDs: m.delta.participants || []
|
836
|
+
};
|
761
837
|
}
|
762
838
|
|
839
|
+
|
763
840
|
function formatID(id) {
|
764
841
|
if (id != undefined && id != null) {
|
765
842
|
return id.replace(/(fb)?id[:.]/, "");
|
@@ -770,74 +847,73 @@ function formatID(id) {
|
|
770
847
|
}
|
771
848
|
|
772
849
|
function formatMessage(m) {
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
850
|
+
var originalMessage = m.message ? m.message : m;
|
851
|
+
var obj = {
|
852
|
+
type: "message",
|
853
|
+
senderName: originalMessage.sender_name,
|
854
|
+
senderID: formatID(originalMessage.sender_fbid.toString()),
|
855
|
+
participantNames: originalMessage.group_thread_info
|
856
|
+
? originalMessage.group_thread_info.participant_names
|
857
|
+
: [originalMessage.sender_name.split(" ")[0]],
|
858
|
+
participantIDs: originalMessage.group_thread_info
|
859
|
+
? originalMessage.group_thread_info.participant_ids.map(function (v) {
|
860
|
+
return formatID(v.toString());
|
861
|
+
})
|
862
|
+
: [formatID(originalMessage.sender_fbid)],
|
863
|
+
body: originalMessage.body || "",
|
864
|
+
threadID: formatID(
|
865
|
+
(
|
866
|
+
originalMessage.thread_fbid || originalMessage.other_user_fbid
|
867
|
+
).toString()
|
868
|
+
),
|
869
|
+
threadName: originalMessage.group_thread_info
|
870
|
+
? originalMessage.group_thread_info.name
|
871
|
+
: originalMessage.sender_name,
|
872
|
+
location: originalMessage.coordinates ? originalMessage.coordinates : null,
|
873
|
+
messageID: originalMessage.mid
|
874
|
+
? originalMessage.mid.toString()
|
875
|
+
: originalMessage.message_id,
|
876
|
+
attachments: formatAttachment(
|
877
|
+
originalMessage.attachments,
|
878
|
+
originalMessage.attachmentIds,
|
879
|
+
originalMessage.attachment_map,
|
880
|
+
originalMessage.share_map
|
881
|
+
),
|
882
|
+
timestamp: originalMessage.timestamp,
|
883
|
+
timestampAbsolute: originalMessage.timestamp_absolute,
|
884
|
+
timestampRelative: originalMessage.timestamp_relative,
|
885
|
+
timestampDatetime: originalMessage.timestamp_datetime,
|
886
|
+
tags: originalMessage.tags,
|
887
|
+
reactions: originalMessage.reactions ? originalMessage.reactions : [],
|
888
|
+
isUnread: originalMessage.is_unread
|
889
|
+
};
|
890
|
+
|
891
|
+
if (m.type === "pages_messaging")
|
892
|
+
obj.pageID = m.realtime_viewer_fbid.toString();
|
893
|
+
obj.isGroup = obj.participantIDs.length > 2;
|
894
|
+
|
895
|
+
return obj;
|
819
896
|
}
|
820
897
|
|
821
898
|
function formatEvent(m) {
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
}
|
899
|
+
var originalMessage = m.message ? m.message : m;
|
900
|
+
var logMessageType = originalMessage.log_message_type;
|
901
|
+
var logMessageData;
|
902
|
+
if (logMessageType === "log:generic-admin-text") {
|
903
|
+
logMessageData = originalMessage.log_message_data.untypedData;
|
904
|
+
logMessageType = getAdminTextMessageType(
|
905
|
+
originalMessage.log_message_data.message_type
|
906
|
+
);
|
907
|
+
} else {
|
908
|
+
logMessageData = originalMessage.log_message_data;
|
909
|
+
}
|
834
910
|
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
911
|
+
return Object.assign(formatMessage(originalMessage), {
|
912
|
+
type: "event",
|
913
|
+
logMessageType: logMessageType,
|
914
|
+
logMessageData: logMessageData,
|
915
|
+
logMessageBody: originalMessage.log_message_body
|
916
|
+
});
|
841
917
|
}
|
842
918
|
|
843
919
|
function formatHistoryMessage(m) {
|
@@ -851,87 +927,71 @@ function formatHistoryMessage(m) {
|
|
851
927
|
|
852
928
|
// Get a more readable message type for AdminTextMessages
|
853
929
|
function getAdminTextMessageType(type) {
|
854
|
-
|
855
|
-
case
|
856
|
-
return
|
857
|
-
case
|
858
|
-
return
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
case "participant_joined_group_call":
|
874
|
-
return "log:thread-call";
|
875
|
-
default:
|
876
|
-
return type;
|
877
|
-
}
|
930
|
+
switch (type) {
|
931
|
+
case "change_thread_theme":
|
932
|
+
return "log:thread-color";
|
933
|
+
case "change_thread_quick_reaction":
|
934
|
+
return "log:thread-icon";
|
935
|
+
case "change_thread_nickname":
|
936
|
+
return "log:user-nickname";
|
937
|
+
case "change_thread_admins":
|
938
|
+
return "log:thread-admins";
|
939
|
+
case "group_poll":
|
940
|
+
return "log:thread-poll";
|
941
|
+
case "change_thread_approval_mode":
|
942
|
+
return "log:thread-approval-mode";
|
943
|
+
case "messenger_call_log":
|
944
|
+
case "participant_joined_group_call":
|
945
|
+
return "log:thread-call";
|
946
|
+
default:
|
947
|
+
return type;
|
948
|
+
}
|
878
949
|
}
|
879
950
|
|
880
951
|
function formatDeltaEvent(m) {
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
m.messageMetadata.threadKey.otherUserFbId
|
925
|
-
).toString()
|
926
|
-
),
|
927
|
-
messageID: m.messageMetadata.messageId.toString(),
|
928
|
-
logMessageType,
|
929
|
-
logMessageData,
|
930
|
-
logMessageBody: m.messageMetadata.adminText,
|
931
|
-
timestamp: m.messageMetadata.timestamp,
|
932
|
-
author: m.messageMetadata.actorFbId,
|
933
|
-
participantIDs: m.participants
|
934
|
-
};
|
952
|
+
var logMessageType;
|
953
|
+
var logMessageData;
|
954
|
+
|
955
|
+
// log:thread-color => {theme_color}
|
956
|
+
// log:user-nickname => {participant_id, nickname}
|
957
|
+
// log:thread-icon => {thread_icon}
|
958
|
+
// log:thread-name => {name}
|
959
|
+
// log:subscribe => {addedParticipants - [Array]}
|
960
|
+
// log:unsubscribe => {leftParticipantFbId}
|
961
|
+
|
962
|
+
switch (m.class) {
|
963
|
+
case "AdminTextMessage":
|
964
|
+
logMessageType = getAdminTextMessageType(m.type);
|
965
|
+
logMessageData = m.untypedData;
|
966
|
+
break;
|
967
|
+
case "ThreadName":
|
968
|
+
logMessageType = "log:thread-name";
|
969
|
+
logMessageData = { name: m.name };
|
970
|
+
break;
|
971
|
+
case "ParticipantsAddedToGroupThread":
|
972
|
+
logMessageType = "log:subscribe";
|
973
|
+
logMessageData = { addedParticipants: m.addedParticipants };
|
974
|
+
break;
|
975
|
+
case "ParticipantLeftGroupThread":
|
976
|
+
logMessageType = "log:unsubscribe";
|
977
|
+
logMessageData = { leftParticipantFbId: m.leftParticipantFbId };
|
978
|
+
break;
|
979
|
+
}
|
980
|
+
|
981
|
+
return {
|
982
|
+
type: "event",
|
983
|
+
threadID: formatID(
|
984
|
+
(
|
985
|
+
m.messageMetadata.threadKey.threadFbId ||
|
986
|
+
m.messageMetadata.threadKey.otherUserFbId
|
987
|
+
).toString()
|
988
|
+
),
|
989
|
+
logMessageType: logMessageType,
|
990
|
+
logMessageData: logMessageData,
|
991
|
+
logMessageBody: m.messageMetadata.adminText,
|
992
|
+
author: m.messageMetadata.actorFbId,
|
993
|
+
participantIDs: m.participants || []
|
994
|
+
};
|
935
995
|
}
|
936
996
|
|
937
997
|
function formatTyp(event) {
|
@@ -991,7 +1051,7 @@ function getFrom(str, startToken, endToken) {
|
|
991
1051
|
const lastHalf = str.substring(start);
|
992
1052
|
const end = lastHalf.indexOf(endToken);
|
993
1053
|
if (end === -1) {
|
994
|
-
throw Error(
|
1054
|
+
throw new Error(
|
995
1055
|
"Could not find endTime `" + endToken + "` in the given string."
|
996
1056
|
);
|
997
1057
|
}
|
@@ -1048,6 +1108,21 @@ function makeDefaults(html, userID, ctx) {
|
|
1048
1108
|
let reqCounter = 1;
|
1049
1109
|
const fb_dtsg = getFrom(html, 'name="fb_dtsg" value="', '"');
|
1050
1110
|
|
1111
|
+
// @Hack Ok we've done hacky things, this is definitely on top 5.
|
1112
|
+
// We totally assume the object is flat and try parsing until a }.
|
1113
|
+
// If it works though it's cool because we get a bunch of extra data things.
|
1114
|
+
//
|
1115
|
+
// Update: we don't need this. Leaving it in in case we ever do.
|
1116
|
+
// Ben - July 15th 2017
|
1117
|
+
|
1118
|
+
// var siteData = getFrom(html, "[\"SiteData\",[],", "},");
|
1119
|
+
// try {
|
1120
|
+
// siteData = JSON.parse(siteData + "}");
|
1121
|
+
// } catch(e) {
|
1122
|
+
// log.warn("makeDefaults", "Couldn't parse SiteData. Won't have access to some variables.");
|
1123
|
+
// siteData = {};
|
1124
|
+
// }
|
1125
|
+
|
1051
1126
|
let ttstamp = "2";
|
1052
1127
|
for (let i = 0; i < fb_dtsg.length; i++) {
|
1053
1128
|
ttstamp += fb_dtsg.charCodeAt(i);
|
@@ -1055,108 +1130,189 @@ function makeDefaults(html, userID, ctx) {
|
|
1055
1130
|
const revision = getFrom(html, 'revision":', ",");
|
1056
1131
|
|
1057
1132
|
function mergeWithDefaults(obj) {
|
1133
|
+
// @TODO This is missing a key called __dyn.
|
1134
|
+
// After some investigation it seems like __dyn is some sort of set that FB
|
1135
|
+
// calls BitMap. It seems like certain responses have a "define" key in the
|
1136
|
+
// res.jsmods arrays. I think the code iterates over those and calls `set`
|
1137
|
+
// on the bitmap for each of those keys. Then it calls
|
1138
|
+
// bitmap.toCompressedString() which returns what __dyn is.
|
1139
|
+
//
|
1140
|
+
// So far the API has been working without this.
|
1141
|
+
//
|
1142
|
+
// Ben - July 15th 2017
|
1058
1143
|
const newObj = {
|
1059
|
-
av: userID,
|
1060
1144
|
__user: userID,
|
1061
1145
|
__req: (reqCounter++).toString(36),
|
1062
1146
|
__rev: revision,
|
1063
1147
|
__a: 1,
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1148
|
+
// __af: siteData.features,
|
1149
|
+
fb_dtsg: ctx.fb_dtsg ? ctx.fb_dtsg : fb_dtsg,
|
1150
|
+
jazoest: ctx.ttstamp ? ctx.ttstamp : ttstamp
|
1151
|
+
// __spin_r: siteData.__spin_r,
|
1152
|
+
// __spin_b: siteData.__spin_b,
|
1153
|
+
// __spin_t: siteData.__spin_t,
|
1154
|
+
};
|
1155
|
+
|
1156
|
+
// @TODO this is probably not needed.
|
1157
|
+
// Ben - July 15th 2017
|
1158
|
+
// if (siteData.be_key) {
|
1159
|
+
// newObj[siteData.be_key] = siteData.be_mode;
|
1160
|
+
// }
|
1161
|
+
// if (siteData.pkg_cohort_key) {
|
1162
|
+
// newObj[siteData.pkg_cohort_key] = siteData.pkg_cohort;
|
1163
|
+
// }
|
1067
1164
|
|
1068
1165
|
if (!obj) return newObj;
|
1069
1166
|
|
1070
|
-
for (
|
1167
|
+
for (const prop in obj) {
|
1071
1168
|
if (obj.hasOwnProperty(prop)) {
|
1072
|
-
if (!newObj[prop])
|
1073
|
-
|
1169
|
+
if (!newObj[prop]) {
|
1170
|
+
newObj[prop] = obj[prop];
|
1171
|
+
}
|
1074
1172
|
}
|
1075
1173
|
}
|
1076
1174
|
|
1077
1175
|
return newObj;
|
1078
1176
|
}
|
1079
1177
|
|
1178
|
+
function postWithDefaults(url, jar, form, ctxx, customHeader = {}) {
|
1179
|
+
return post(url, jar, mergeWithDefaults(form), ctx.globalOptions, ctxx || ctx, customHeader);
|
1180
|
+
}
|
1181
|
+
|
1182
|
+
function getWithDefaults(url, jar, qs, ctxx, customHeader = {}) {
|
1183
|
+
return get(url, jar, mergeWithDefaults(qs), ctx.globalOptions, ctxx || ctx, customHeader);
|
1184
|
+
}
|
1185
|
+
|
1186
|
+
function postFormDataWithDefault(url, jar, form, qs, ctxx) {
|
1187
|
+
return postFormData(
|
1188
|
+
url,
|
1189
|
+
jar,
|
1190
|
+
mergeWithDefaults(form),
|
1191
|
+
mergeWithDefaults(qs),
|
1192
|
+
ctx.globalOptions,
|
1193
|
+
ctxx || ctx
|
1194
|
+
);
|
1195
|
+
}
|
1196
|
+
|
1080
1197
|
return {
|
1081
|
-
get:
|
1082
|
-
post:
|
1083
|
-
postFormData:
|
1198
|
+
get: getWithDefaults,
|
1199
|
+
post: postWithDefaults,
|
1200
|
+
postFormData: postFormDataWithDefault
|
1084
1201
|
};
|
1085
1202
|
}
|
1086
1203
|
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1204
|
+
//Fix parseAndCheckLogin
|
1205
|
+
function parseAndCheckLogin(ctx, defaultFuncs, retryCount, sourceCall) {
|
1206
|
+
if (retryCount == undefined) {
|
1207
|
+
retryCount = 0;
|
1208
|
+
}
|
1209
|
+
if (sourceCall == undefined) {
|
1210
|
+
try {
|
1211
|
+
throw new Error();
|
1212
|
+
}
|
1213
|
+
catch (e) {
|
1214
|
+
sourceCall = e;
|
1215
|
+
}
|
1216
|
+
}
|
1098
1217
|
return function (data) {
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1218
|
+
return tryPromise(function () {
|
1219
|
+
log.verbose("parseAndCheckLogin", data.body);
|
1220
|
+
if (data.statusCode >= 500 && data.statusCode < 600) {
|
1221
|
+
if (retryCount >= 5) {
|
1222
|
+
throw new CustomError({
|
1223
|
+
message: "Request retry failed. Check the `res` and `statusCode` property on this error.",
|
1224
|
+
statusCode: data.statusCode,
|
1225
|
+
res: data.body,
|
1226
|
+
error: "Request retry failed. Check the `res` and `statusCode` property on this error.",
|
1227
|
+
sourceCall: sourceCall
|
1228
|
+
});
|
1229
|
+
}
|
1230
|
+
retryCount++;
|
1231
|
+
const retryTime = Math.floor(Math.random() * 5000);
|
1232
|
+
log.warn(
|
1233
|
+
"parseAndCheckLogin",
|
1234
|
+
"Got status code " +
|
1235
|
+
data.statusCode +
|
1236
|
+
" - " +
|
1237
|
+
retryCount +
|
1238
|
+
". attempt to retry in " +
|
1239
|
+
retryTime +
|
1240
|
+
" milliseconds..."
|
1241
|
+
);
|
1242
|
+
const url =
|
1243
|
+
data.request.uri.protocol +
|
1244
|
+
"//" +
|
1245
|
+
data.request.uri.hostname +
|
1246
|
+
data.request.uri.pathname;
|
1247
|
+
if (
|
1248
|
+
data.request.headers["Content-Type"].split(";")[0] ===
|
1249
|
+
"multipart/form-data"
|
1250
|
+
) {
|
1113
1251
|
return delay(retryTime)
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1252
|
+
.then(function () {
|
1253
|
+
return defaultFuncs.postFormData(
|
1254
|
+
url,
|
1255
|
+
ctx.jar,
|
1256
|
+
data.request.formData,
|
1257
|
+
{}
|
1258
|
+
);
|
1259
|
+
})
|
1260
|
+
.then(parseAndCheckLogin(ctx, defaultFuncs, retryCount, sourceCall));
|
1261
|
+
}
|
1262
|
+
else {
|
1263
|
+
return delay(retryTime)
|
1264
|
+
.then(function () {
|
1265
|
+
return defaultFuncs.post(url, ctx.jar, data.request.formData);
|
1266
|
+
})
|
1267
|
+
.then(parseAndCheckLogin(ctx, defaultFuncs, retryCount, sourceCall));
|
1268
|
+
}
|
1269
|
+
}
|
1270
|
+
if (data.statusCose === 404) return;
|
1271
|
+
if (data.statusCode !== 200)
|
1272
|
+
throw new CustomError({
|
1273
|
+
message: "parseAndCheckLogin got status code: " + data.statusCode + ". Bailing out of trying to parse response.",
|
1274
|
+
statusCode: data.statusCode,
|
1275
|
+
res: data.body,
|
1276
|
+
error: "parseAndCheckLogin got status code: " + data.statusCode + ". Bailing out of trying to parse response.",
|
1277
|
+
sourceCall: sourceCall
|
1278
|
+
});
|
1279
|
+
|
1280
|
+
let res = null;
|
1136
1281
|
try {
|
1137
1282
|
res = JSON.parse(makeParsable(data.body));
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1283
|
+
} catch (e) {
|
1284
|
+
throw new CustomError({
|
1285
|
+
message: "JSON.parse error. Check the `detail` property on this error.",
|
1286
|
+
detail: e,
|
1287
|
+
res: data.body,
|
1288
|
+
error: "JSON.parse error. Check the `detail` property on this error.",
|
1289
|
+
sourceCall: sourceCall
|
1290
|
+
});
|
1144
1291
|
}
|
1145
1292
|
|
1146
1293
|
// In some cases the response contains only a redirect URL which should be followed
|
1147
1294
|
if (res.redirect && data.request.method === "GET") {
|
1148
|
-
return
|
1295
|
+
return defaultFuncs
|
1149
1296
|
.get(res.redirect, ctx.jar)
|
1150
|
-
.then(parseAndCheckLogin(ctx,
|
1151
|
-
|
1297
|
+
.then(parseAndCheckLogin(ctx, defaultFuncs, undefined, sourceCall));
|
1298
|
+
}
|
1152
1299
|
|
1153
1300
|
// TODO: handle multiple cookies?
|
1154
|
-
if (
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1301
|
+
if (
|
1302
|
+
res.jsmods &&
|
1303
|
+
res.jsmods.require &&
|
1304
|
+
Array.isArray(res.jsmods.require[0]) &&
|
1305
|
+
res.jsmods.require[0][0] === "Cookie"
|
1306
|
+
) {
|
1307
|
+
res.jsmods.require[0][3][0] = res.jsmods.require[0][3][0].replace(
|
1308
|
+
"_js_",
|
1309
|
+
""
|
1310
|
+
);
|
1311
|
+
const cookie = formatCookie(res.jsmods.require[0][3], "facebook");
|
1312
|
+
const cookie2 = formatCookie(res.jsmods.require[0][3], "messenger");
|
1313
|
+
ctx.jar.setCookie(cookie, "https://www.facebook.com");
|
1314
|
+
ctx.jar.setCookie(cookie2, "https://www.messenger.com");
|
1315
|
+
}
|
1160
1316
|
|
1161
1317
|
// On every request we check if we got a DTSG and we mutate the context so that we use the latest
|
1162
1318
|
// one for the next requests.
|
@@ -1176,13 +1332,16 @@ function parseAndCheckLogin(ctx, http, retryCount) {
|
|
1176
1332
|
}
|
1177
1333
|
|
1178
1334
|
if (res.error === 1357001) {
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1335
|
+
throw new CustomError({
|
1336
|
+
message: "Facebook blocked login. Please visit https://facebook.com and check your account.",
|
1337
|
+
error: "Not logged in.",
|
1338
|
+
res: res,
|
1339
|
+
statusCode: data.statusCode,
|
1340
|
+
sourceCall: sourceCall
|
1341
|
+
});
|
1182
1342
|
}
|
1183
1343
|
return res;
|
1184
|
-
}
|
1185
|
-
return _try(any);
|
1344
|
+
});
|
1186
1345
|
};
|
1187
1346
|
}
|
1188
1347
|
|
@@ -1249,39 +1408,39 @@ function formatCookie(arr, url) {
|
|
1249
1408
|
}
|
1250
1409
|
|
1251
1410
|
function formatThread(data) {
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1411
|
+
return {
|
1412
|
+
threadID: formatID(data.thread_fbid.toString()),
|
1413
|
+
participants: data.participants.map(formatID),
|
1414
|
+
participantIDs: data.participants.map(formatID),
|
1415
|
+
name: data.name,
|
1416
|
+
nicknames: data.custom_nickname,
|
1417
|
+
snippet: data.snippet,
|
1418
|
+
snippetAttachments: data.snippet_attachments,
|
1419
|
+
snippetSender: formatID((data.snippet_sender || "").toString()),
|
1420
|
+
unreadCount: data.unread_count,
|
1421
|
+
messageCount: data.message_count,
|
1422
|
+
imageSrc: data.image_src,
|
1423
|
+
timestamp: data.timestamp,
|
1424
|
+
serverTimestamp: data.server_timestamp, // what is this?
|
1425
|
+
muteUntil: data.mute_until,
|
1426
|
+
isCanonicalUser: data.is_canonical_user,
|
1427
|
+
isCanonical: data.is_canonical,
|
1428
|
+
isSubscribed: data.is_subscribed,
|
1429
|
+
folder: data.folder,
|
1430
|
+
isArchived: data.is_archived,
|
1431
|
+
recipientsLoadable: data.recipients_loadable,
|
1432
|
+
hasEmailParticipant: data.has_email_participant,
|
1433
|
+
readOnly: data.read_only,
|
1434
|
+
canReply: data.can_reply,
|
1435
|
+
cannotReplyReason: data.cannot_reply_reason,
|
1436
|
+
lastMessageTimestamp: data.last_message_timestamp,
|
1437
|
+
lastReadTimestamp: data.last_read_timestamp,
|
1438
|
+
lastMessageType: data.last_message_type,
|
1439
|
+
emoji: data.custom_like_icon,
|
1440
|
+
color: data.custom_color,
|
1441
|
+
adminIDs: data.admin_ids,
|
1442
|
+
threadType: data.thread_type
|
1443
|
+
};
|
1285
1444
|
}
|
1286
1445
|
|
1287
1446
|
function getType(obj) {
|
@@ -1307,6 +1466,34 @@ function formatPresence(presence, userID) {
|
|
1307
1466
|
};
|
1308
1467
|
}
|
1309
1468
|
|
1469
|
+
function getFroms(str, startToken, endToken) {
|
1470
|
+
//advanced search by kanzuuuuuuuuuu
|
1471
|
+
let results = [];
|
1472
|
+
let currentIndex = 0;
|
1473
|
+
|
1474
|
+
while (true) {
|
1475
|
+
let start = str.indexOf(startToken, currentIndex);
|
1476
|
+
if (start === -1) break;
|
1477
|
+
|
1478
|
+
start += startToken.length;
|
1479
|
+
|
1480
|
+
let lastHalf = str.substring(start);
|
1481
|
+
let end = lastHalf.indexOf(endToken);
|
1482
|
+
|
1483
|
+
if (end === -1) {
|
1484
|
+
if (results.length === 0) {
|
1485
|
+
throw Error("Could not find endToken `" + endToken + "` in the given string.");
|
1486
|
+
}
|
1487
|
+
break;
|
1488
|
+
}
|
1489
|
+
|
1490
|
+
results.push(lastHalf.substring(0, end));
|
1491
|
+
currentIndex = start + end + endToken.length;
|
1492
|
+
}
|
1493
|
+
|
1494
|
+
return results.length === 0 ? "" : results.length === 1 ? results[0] : results;
|
1495
|
+
}
|
1496
|
+
|
1310
1497
|
function decodeClientPayload(payload) {
|
1311
1498
|
/*
|
1312
1499
|
Special function which Client using to "encode" clients JSON payload
|
@@ -1315,26 +1502,14 @@ function decodeClientPayload(payload) {
|
|
1315
1502
|
}
|
1316
1503
|
|
1317
1504
|
function getAppState(jar) {
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
function getAccessFromBusiness(jar, Options) {
|
1324
|
-
return function (res) {
|
1325
|
-
var html = res ? res.body : null;
|
1326
|
-
return get('https://business.facebook.com/content_management', jar, null, Options, null, { noRef: true })
|
1327
|
-
.then(function (res) {
|
1328
|
-
var token = /"accessToken":"([^.]+)","clientID":/g.exec(res.body)[1];
|
1329
|
-
return [html, token];
|
1330
|
-
})
|
1331
|
-
.catch(function () {
|
1332
|
-
return [html, null];
|
1333
|
-
});
|
1334
|
-
}
|
1505
|
+
return jar
|
1506
|
+
.getCookies("https://www.facebook.com")
|
1507
|
+
.concat(jar.getCookies("https://facebook.com"))
|
1508
|
+
.concat(jar.getCookies("https://www.messenger.com"));
|
1335
1509
|
}
|
1336
1510
|
|
1337
1511
|
module.exports = {
|
1512
|
+
CustomError,
|
1338
1513
|
isReadableStream,
|
1339
1514
|
get,
|
1340
1515
|
post,
|
@@ -1373,7 +1548,5 @@ module.exports = {
|
|
1373
1548
|
getAppState,
|
1374
1549
|
getAdminTextMessageType,
|
1375
1550
|
setProxy,
|
1376
|
-
|
1377
|
-
|
1378
|
-
presenceEncode
|
1379
|
-
}
|
1551
|
+
getFroms
|
1552
|
+
};
|