@dongdev/fca-unofficial 0.0.2 → 0.0.3

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 (2) hide show
  1. package/index.js +111 -94
  2. package/package.json +23 -56
package/index.js CHANGED
@@ -10,70 +10,73 @@ var defaultLogRecordSize = 100;
10
10
  log.maxRecordSize = defaultLogRecordSize;
11
11
 
12
12
  function setOptions(globalOptions, options) {
13
- Object.keys(options).map(function (key) {
14
- switch (key) {
15
- case 'pauseLog':
16
- if (options.pauseLog) log.pause();
17
- break;
18
- case 'online':
19
- globalOptions.online = Boolean(options.online);
20
- break;
21
- case 'logLevel':
22
- log.level = options.logLevel;
23
- globalOptions.logLevel = options.logLevel;
24
- break;
25
- case 'logRecordSize':
26
- log.maxRecordSize = options.logRecordSize;
27
- globalOptions.logRecordSize = options.logRecordSize;
28
- break;
29
- case 'selfListen':
30
- globalOptions.selfListen = Boolean(options.selfListen);
31
- break;
32
- case 'listenEvents':
33
- globalOptions.listenEvents = Boolean(options.listenEvents);
34
- break;
35
- case 'pageID':
36
- globalOptions.pageID = options.pageID.toString();
37
- break;
38
- case 'updatePresence':
39
- globalOptions.updatePresence = Boolean(options.updatePresence);
40
- break;
41
- case 'forceLogin':
42
- globalOptions.forceLogin = Boolean(options.forceLogin);
43
- break;
44
- case 'userAgent':
45
- globalOptions.userAgent = options.userAgent;
46
- break;
47
- case 'autoMarkDelivery':
48
- globalOptions.autoMarkDelivery = Boolean(options.autoMarkDelivery);
49
- break;
50
- case 'autoMarkRead':
51
- globalOptions.autoMarkRead = Boolean(options.autoMarkRead);
52
- break;
53
- case 'listenTyping':
54
- globalOptions.listenTyping = Boolean(options.listenTyping);
55
- break;
56
- case 'proxy':
57
- if (typeof options.proxy != "string") {
58
- delete globalOptions.proxy;
59
- utils.setProxy();
60
- }
61
- else {
62
- globalOptions.proxy = options.proxy;
63
- utils.setProxy(globalOptions.proxy);
64
- }
65
- break;
66
- case 'autoReconnect':
67
- globalOptions.autoReconnect = Boolean(options.autoReconnect);
68
- break;
69
- case 'emitReady':
70
- globalOptions.emitReady = Boolean(options.emitReady);
71
- break;
72
- default:
73
- log.warn("setOptions", "Unrecognized option given to setOptions: " + key);
74
- break;
75
- }
76
- });
13
+ if (options && typeof options === 'object') {
14
+ Object.keys(options).map(function (key) {
15
+ switch (key) {
16
+ case 'pauseLog':
17
+ if (options.pauseLog) log.pause();
18
+ break;
19
+ case 'online':
20
+ globalOptions.online = Boolean(options.online);
21
+ break;
22
+ case 'logLevel':
23
+ log.level = options.logLevel;
24
+ globalOptions.logLevel = options.logLevel;
25
+ break;
26
+ case 'logRecordSize':
27
+ log.maxRecordSize = options.logRecordSize;
28
+ globalOptions.logRecordSize = options.logRecordSize;
29
+ break;
30
+ case 'selfListen':
31
+ globalOptions.selfListen = Boolean(options.selfListen);
32
+ break;
33
+ case 'listenEvents':
34
+ globalOptions.listenEvents = Boolean(options.listenEvents);
35
+ break;
36
+ case 'pageID':
37
+ globalOptions.pageID = options.pageID.toString();
38
+ break;
39
+ case 'updatePresence':
40
+ globalOptions.updatePresence = Boolean(options.updatePresence);
41
+ break;
42
+ case 'forceLogin':
43
+ globalOptions.forceLogin = Boolean(options.forceLogin);
44
+ break;
45
+ case 'userAgent':
46
+ globalOptions.userAgent = options.userAgent;
47
+ break;
48
+ case 'autoMarkDelivery':
49
+ globalOptions.autoMarkDelivery = Boolean(options.autoMarkDelivery);
50
+ break;
51
+ case 'autoMarkRead':
52
+ globalOptions.autoMarkRead = Boolean(options.autoMarkRead);
53
+ break;
54
+ case 'listenTyping':
55
+ globalOptions.listenTyping = Boolean(options.listenTyping);
56
+ break;
57
+ case 'proxy':
58
+ if (typeof options.proxy != "string") {
59
+ delete globalOptions.proxy;
60
+ utils.setProxy();
61
+ } else {
62
+ globalOptions.proxy = options.proxy;
63
+ utils.setProxy(globalOptions.proxy);
64
+ }
65
+ break;
66
+ case 'autoReconnect':
67
+ globalOptions.autoReconnect = Boolean(options.autoReconnect);
68
+ break;
69
+ case 'emitReady':
70
+ globalOptions.emitReady = Boolean(options.emitReady);
71
+ break;
72
+ default:
73
+ log.warn("setOptions", "Unrecognized option given to setOptions: " + key);
74
+ break;
75
+ }
76
+ });
77
+ } else {
78
+ log.warn("setOptions", "Invalid or undefined options provided.");
79
+ }
77
80
  }
78
81
 
79
82
  function buildAPI(globalOptions, html, jar) {
@@ -453,36 +456,50 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
453
456
 
454
457
  var redirect = [1, "https://m.facebook.com/"], bypass_region_err = false, ctx, _defaultFuncs, api;
455
458
  function CheckAndFixErr(res) {
456
- if (/This browser is not supported/gs.test(res.body)) {
457
- let fid = (res.body.split('2Fhome.php&gfid=')[1] || '').split("\\")[0];
458
- if (!fid) return res;
459
- bypass_region_err = true;
460
- let redirectlink = `${redirect[1]}a/preferences.php?basic_site_devices=m_basic&uri=${encodeURIComponent("https://m.facebook.com/home.php")}&gfid=${fid}`;
461
- return utils.get(redirectlink, jar, null, globalOptions).then(utils.saveCookies(jar));
462
- }
463
- return res;
464
- }
465
- function Redirect(res) {
466
- let match = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/.exec(res.body);
467
- return match ? utils.get(match[1], jar, null, globalOptions).then(utils.saveCookies(jar)) : res;
468
- }
469
- mainPromise = mainPromise
470
- .then(Redirect)
471
- .then(CheckAndFixErr)
472
- .then(res => {
473
- if (!/MPageLoadClientMetrics/gs.test(res.body)) {
474
- globalOptions.userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X)";
475
- return utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
476
- }
477
- return res;
478
- })
479
- .then(Redirect)
480
- .then(CheckAndFixErr)
481
- .then(res => {
482
- let stuff = buildAPI(globalOptions, res.body, jar, bypass_region_err);
483
- [ctx, _defaultFuncs, api] = stuff;
484
- return res;
485
- });
459
+ let reg_antierr = /This browser is not supported/gs;
460
+ if (reg_antierr.test(res.body)) {
461
+ const Data = JSON.stringify(res.body);
462
+ const Dt_Check = Data.split('2Fhome.php&amp;gfid=')[1];
463
+ if (Dt_Check == undefined) return res
464
+ const fid = Dt_Check.split("\\\\")[0];
465
+ if (Dt_Check == undefined || Dt_Check == "") return res
466
+ const final_fid = fid.split(`\\`)[0];
467
+ if (final_fid == undefined || final_fid == '') return res;
468
+ const redirectlink = redirect[1] + "a/preferences.php?basic_site_devices=m_basic&uri=" + encodeURIComponent("https://m.facebook.com/home.php") + "&gfid=" + final_fid;
469
+ bypass_region_err = true;
470
+ log.info('login', 'Bypass vùng tài khoản thành công');
471
+ return utils.get(redirectlink, jar, null, globalOptions).then(utils.saveCookies(jar));
472
+ }
473
+ else return res
474
+ }
475
+ function Redirect(res) {
476
+ var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
477
+ redirect = reg.exec(res.body);
478
+ if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
479
+ return res;
480
+ }
481
+
482
+ mainPromise = mainPromise
483
+ .then(res => Redirect(res))
484
+ .then(res => CheckAndFixErr(res))
485
+ .then(function(res) {
486
+ let Regex_Via = /MPageLoadClientMetrics/gs;
487
+ if (!Regex_Via.test(res.body)) {
488
+ globalOptions.userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1";
489
+ return utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
490
+ }
491
+ else return res
492
+ })
493
+ .then(res => Redirect(res))
494
+ .then(res => CheckAndFixErr(res))
495
+ .then(function (res) {
496
+ var html = res.body;
497
+ var stuff = buildAPI(globalOptions, html, jar, bypass_region_err);
498
+ ctx = stuff[0];
499
+ _defaultFuncs = stuff[1];
500
+ api = stuff[2];
501
+ return res;
502
+ });
486
503
 
487
504
  // given a pageID we log in as a page
488
505
  if (globalOptions.pageID) {
package/package.json CHANGED
@@ -1,24 +1,11 @@
1
1
  {
2
2
  "name": "@dongdev/fca-unofficial",
3
- "version": "0.0.2",
4
- "description": "A Facebook chat API that doesn't rely on XMPP. Will NOT be deprecated after April 30th 2015.",
5
- "scripts": {
6
- "test": "mocha",
7
- "lint": "eslint **.js",
8
- "prettier": "prettier utils.js src/* --write"
9
- },
3
+ "version": "0.0.3",
4
+ "description": "A Facebook chat API without XMPP, will not be deprecated after April 30th, 2015.",
5
+ "main": "index.js",
10
6
  "repository": {
11
7
  "type": "git",
12
- "url": "git://github.com/DongDevVN/fca-unofficial.git"
13
- },
14
- "keywords": [
15
- "facebook",
16
- "chat",
17
- "api",
18
- "fca"
19
- ],
20
- "bugs": {
21
- "url": "https://github.com/DongDevVN/fca-unofficial/issues"
8
+ "url": "https://github.com/DongDev-VN/fca-unofficial.git"
22
9
  },
23
10
  "author": "Avery, David, Maude, Benjamin, UIRI, MiraiTeam",
24
11
  "license": "MIT",
@@ -31,51 +18,31 @@
31
18
  "request": "^2.53.0",
32
19
  "websocket-stream": "^5.5.0"
33
20
  },
34
- "engines": {
35
- "node": ">=10.x"
36
- },
37
21
  "devDependencies": {
38
22
  "eslint": "^7.5.0",
39
23
  "mocha": "^7.0.1",
40
24
  "prettier": "^1.11.1"
41
25
  },
42
- "eslintConfig": {
43
- "env": {
44
- "es6": true,
45
- "es2017": true,
46
- "node": true
47
- },
48
- "extends": "eslint:recommended",
49
- "parserOptions": {
50
- "sourceType": "module"
51
- },
52
- "rules": {
53
- "linebreak-style": [
54
- "error",
55
- "unix"
56
- ],
57
- "semi": [
58
- "error",
59
- "always"
60
- ],
61
- "no-unused-vars": [
62
- 1,
63
- {
64
- "argsIgnorePattern": "^_",
65
- "varsIgnorePattern": "^_"
66
- }
67
- ],
68
- "no-empty": [
69
- "error",
70
- {
71
- "allowEmptyCatch": true
72
- }
73
- ]
74
- }
26
+ "scripts": {
27
+ "test": "mocha",
28
+ "lint": "eslint **/*.js",
29
+ "prettier": "prettier utils.js src/* --write"
30
+ },
31
+ "keywords": [
32
+ "facebook",
33
+ "chat",
34
+ "api",
35
+ "fca",
36
+ "facebook-chat-api"
37
+ ],
38
+ "engines": {
39
+ "node": ">=10.x"
40
+ },
41
+ "homepage": "https://github.com/DongDev-VN/fca-unofficial#readme",
42
+ "bugs": {
43
+ "url": "https://github.com/DongDev-VN/fca-unofficial/issues"
75
44
  },
76
- "homepage": "https://github.com/DongDevVN/fca-unofficial#readme",
77
- "main": "index.js",
78
45
  "directories": {
79
46
  "test": "test"
80
47
  }
81
- }
48
+ }