fca-nx 7.3.5 → 7.5.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/README.md +9 -7
- package/module/loginHelper.js +71 -125
- package/package.json +1 -1
- package/src/api/action/acceptFriendRequest.js +126 -0
- package/src/api/socket/core/connectMqtt.js +56 -16
- package/src/api/socket/core/emitAuth.js +4 -1
- package/src/api/socket/core/getSeqID.js +106 -6
- package/src/api/socket/listenMqtt.js +14 -43
- package/src/api/users/getCoverPhoto.js +86 -0
- package/src/api/users/getUserInfoV2.js +15 -93
- package/src/app/createFcaClient.js +2 -0
- package/src/utils/loginParser/autoLogin.js +30 -0
- package/src/utils/sendThrottle.js +7 -14
- package/src/utils/sessionStatus.js +112 -0
|
@@ -3,35 +3,25 @@ const { parseAndCheckLogin } = require("../../utils/client.js");
|
|
|
3
3
|
const logger = require("../../../func/logger");
|
|
4
4
|
|
|
5
5
|
const DOC_IDS = [
|
|
6
|
-
{
|
|
7
|
-
id: "2399631849267992",
|
|
8
|
-
name: "CometUserProfileCoverPhotoQuery",
|
|
9
|
-
hasCover: true
|
|
10
|
-
},
|
|
11
6
|
{
|
|
12
7
|
id: "5009315269112105",
|
|
13
|
-
name: "CometProfilePhotoGridQuery"
|
|
14
|
-
hasCover: true
|
|
8
|
+
name: "CometProfilePhotoGridQuery"
|
|
15
9
|
},
|
|
16
10
|
{
|
|
17
11
|
id: "24418640587785718",
|
|
18
|
-
name: "CometHovercardQueryRendererQuery"
|
|
19
|
-
hasCover: false
|
|
12
|
+
name: "CometHovercardQueryRendererQuery"
|
|
20
13
|
},
|
|
21
14
|
{
|
|
22
15
|
id: "6003371686559437",
|
|
23
|
-
name: "CometProfileInfoRendererQuery"
|
|
24
|
-
hasCover: true
|
|
16
|
+
name: "CometProfileInfoRendererQuery"
|
|
25
17
|
},
|
|
26
18
|
{
|
|
27
19
|
id: "6184020922587885",
|
|
28
|
-
name: "CometProfilePageQuery"
|
|
29
|
-
hasCover: true
|
|
20
|
+
name: "CometProfilePageQuery"
|
|
30
21
|
},
|
|
31
22
|
{
|
|
32
23
|
id: "5069749766627730",
|
|
33
|
-
name: "CometActorProfilePictureQuery"
|
|
34
|
-
hasCover: false
|
|
24
|
+
name: "CometActorProfilePictureQuery"
|
|
35
25
|
}
|
|
36
26
|
];
|
|
37
27
|
const CALLER_CLASS = "RelayModern";
|
|
@@ -82,9 +72,7 @@ function extractPhotoUrl(photo, depth = 0) {
|
|
|
82
72
|
"full_image",
|
|
83
73
|
"viewer_image",
|
|
84
74
|
"photo",
|
|
85
|
-
"media"
|
|
86
|
-
"cover_photo",
|
|
87
|
-
"coverPhoto"
|
|
75
|
+
"media"
|
|
88
76
|
]) {
|
|
89
77
|
const value = extractPhotoUrl(photo[key], depth + 1);
|
|
90
78
|
if (value) return value;
|
|
@@ -93,31 +81,6 @@ function extractPhotoUrl(photo, depth = 0) {
|
|
|
93
81
|
}
|
|
94
82
|
|
|
95
83
|
|
|
96
|
-
// [Hardened] Fallback: read the cover photo straight from the profile page HTML,
|
|
97
|
-
// used when none of the GraphQL doc_ids returned a cover (doc_ids rotate often).
|
|
98
|
-
function decodeJsonString(raw) {
|
|
99
|
-
try { return JSON.parse('"' + raw + '"'); } catch { return String(raw).replace(/\\\//g, "/"); }
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function extractCoverFromHTML(html) {
|
|
103
|
-
if (!html || typeof html !== "string") return null;
|
|
104
|
-
const patterns = [
|
|
105
|
-
/"cover_photo"\s*:\s*\{[\s\S]{0,800}?"uri"\s*:\s*"([^"]+)"/,
|
|
106
|
-
/"profile_cover_photo"\s*:\s*\{[\s\S]{0,800}?"uri"\s*:\s*"([^"]+)"/,
|
|
107
|
-
/"coverPhoto"\s*:\s*\{[\s\S]{0,800}?"uri"\s*:\s*"([^"]+)"/,
|
|
108
|
-
/"cover_photo"\s*:\s*\{[\s\S]{0,800}?"url"\s*:\s*"([^"]+)"/,
|
|
109
|
-
/property="og:image"\s+content="(https:\/\/[^"]+fbcdn[^"]+)"/i,
|
|
110
|
-
/content="(https:\/\/[^"]+fbcdn[^"]+)"\s+property="og:image"/i
|
|
111
|
-
];
|
|
112
|
-
for (const re of patterns) {
|
|
113
|
-
const m = html.match(re);
|
|
114
|
-
if (!m) continue;
|
|
115
|
-
const url = decodeJsonString(m[1]).replace(/&/g, "&");
|
|
116
|
-
if (/^https?:\/\//i.test(url) && /(fbcdn|scontent)/i.test(url)) return url;
|
|
117
|
-
}
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
84
|
function pickMeta(user) {
|
|
122
85
|
let friendshipStatus = null;
|
|
123
86
|
let gender = null;
|
|
@@ -142,20 +105,6 @@ function pickMeta(user) {
|
|
|
142
105
|
return { friendshipStatus, gender, shortName };
|
|
143
106
|
}
|
|
144
107
|
|
|
145
|
-
function extractCoverPhoto(user) {
|
|
146
|
-
const cover = user?.cover_photo;
|
|
147
|
-
if (!cover) return null;
|
|
148
|
-
if (typeof cover === "string") return cover;
|
|
149
|
-
return cover.source?.uri ||
|
|
150
|
-
cover.source ||
|
|
151
|
-
cover.uri ||
|
|
152
|
-
cover.photo?.image?.uri ||
|
|
153
|
-
cover.photo?.image?.url ||
|
|
154
|
-
cover.image?.uri ||
|
|
155
|
-
cover.image?.url ||
|
|
156
|
-
cover.photo?.url ||
|
|
157
|
-
null;
|
|
158
|
-
}
|
|
159
108
|
function normalizeUser(user) {
|
|
160
109
|
if (!user) return null;
|
|
161
110
|
const meta = pickMeta(user);
|
|
@@ -166,13 +115,8 @@ function normalizeUser(user) {
|
|
|
166
115
|
firstName: meta.shortName || null,
|
|
167
116
|
vanity,
|
|
168
117
|
thumbSrc: extractProfilePicture(user),
|
|
169
|
-
coverPhoto:
|
|
170
|
-
|
|
171
|
-
extractPhotoUrl(user.coverPhoto) ||
|
|
172
|
-
extractPhotoUrl(user.profile_cover_photo) ||
|
|
173
|
-
extractPhotoUrl(user.cover_photo_renderer) ||
|
|
174
|
-
extractCoverPhoto(user) ||
|
|
175
|
-
null,
|
|
118
|
+
coverPhoto: null,
|
|
119
|
+
coverPhotoStatus: "unavailable",
|
|
176
120
|
profileUrl: user.profile_url || user.url || null,
|
|
177
121
|
gender: meta.gender || null,
|
|
178
122
|
type: user.__typename || "User",
|
|
@@ -196,7 +140,8 @@ function createDefaultUser(id) {
|
|
|
196
140
|
vanity: String(id),
|
|
197
141
|
thumbSrc: `https://graph.facebook.com/${id}/picture?width=720&height=720`,
|
|
198
142
|
profilePicUrl: `https://graph.facebook.com/${id}/picture?width=720&height=720`,
|
|
199
|
-
coverPhoto: null,
|
|
143
|
+
coverPhoto: null,
|
|
144
|
+
coverPhotoStatus: "unavailable",
|
|
200
145
|
profileUrl: `https://www.facebook.com/profile.php?id=${id}`,
|
|
201
146
|
gender: "no specific gender",
|
|
202
147
|
type: "User",
|
|
@@ -223,7 +168,8 @@ function formatUser(user, id) {
|
|
|
223
168
|
lastName: nameParts.length > 1? nameParts.slice(1).join(" ") : null,
|
|
224
169
|
vanity: user.vanity || String(id),
|
|
225
170
|
profilePicUrl: user.thumbSrc || `https://graph.facebook.com/${id}/picture?width=720&height=720`,
|
|
226
|
-
coverPhoto:
|
|
171
|
+
coverPhoto: null,
|
|
172
|
+
coverPhotoStatus: "unavailable",
|
|
227
173
|
profileUrl: user.profileUrl || `https://www.facebook.com/profile.php?id=${id}`,
|
|
228
174
|
gender: user.gender || "no specific gender",
|
|
229
175
|
type: user.type || "User",
|
|
@@ -270,40 +216,16 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
270
216
|
if (!bestUser) {
|
|
271
217
|
bestUser = normalized;
|
|
272
218
|
} else {
|
|
273
|
-
for (const field of ["thumbSrc", "profileUrl", "vanity", "
|
|
219
|
+
for (const field of ["thumbSrc", "profileUrl", "vanity", "firstName", "gender"]) {
|
|
274
220
|
if (!bestUser[field] && normalized[field]) bestUser[field] = normalized[field];
|
|
275
221
|
}
|
|
276
222
|
if (normalized.isVerified) bestUser.isVerified = true;
|
|
277
223
|
if (normalized.isFriend) bestUser.isFriend = true;
|
|
278
224
|
}
|
|
279
|
-
if (doc.hasCover && bestUser.coverPhoto) break;
|
|
280
225
|
} catch (error) {
|
|
281
226
|
logger(`getUserInfoV2 ${doc.id}: ${error.message || error}`, "warn");
|
|
282
227
|
}
|
|
283
228
|
}
|
|
284
|
-
// [Hardened] GraphQL often omits cover; scrape profile HTML as last resort
|
|
285
|
-
if (bestUser && !bestUser.coverPhoto) {
|
|
286
|
-
const pages = [`https://www.facebook.com/profile.php?id=${id}`];
|
|
287
|
-
if (bestUser.vanity && bestUser.vanity !== id) {
|
|
288
|
-
pages.push(`https://www.facebook.com/${bestUser.vanity}`);
|
|
289
|
-
}
|
|
290
|
-
for (const url of pages) {
|
|
291
|
-
try {
|
|
292
|
-
const res = await defaultFuncs.get(url, ctx.jar, null, ctx);
|
|
293
|
-
const html = typeof res === "string" ? res : (res && res.data);
|
|
294
|
-
const cover = extractCoverFromHTML(html);
|
|
295
|
-
if (cover) {
|
|
296
|
-
bestUser.coverPhoto = cover;
|
|
297
|
-
break;
|
|
298
|
-
}
|
|
299
|
-
} catch (error) {
|
|
300
|
-
logger(`getUserInfoV2 cover html ${id}: ${error.message || error}`, "warn");
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
if (!bestUser.coverPhoto && process.env.FCA_COVER_DEBUG === "1") {
|
|
304
|
-
logger(`getUserInfoV2 cover ${id}: no cover found in GraphQL or profile HTML`, "warn");
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
229
|
return bestUser;
|
|
308
230
|
}
|
|
309
231
|
|
|
@@ -329,7 +251,8 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
329
251
|
lastName: nameParts.length > 1? nameParts.slice(1).join(" ") : null,
|
|
330
252
|
vanity: profile.vanity || null,
|
|
331
253
|
thumbSrc: null,
|
|
332
|
-
coverPhoto:
|
|
254
|
+
coverPhoto: null,
|
|
255
|
+
coverPhotoStatus: "unavailable",
|
|
333
256
|
profileUrl: profile.uri || `https://www.facebook.com/profile.php?id=${id}`,
|
|
334
257
|
gender: profile.gender === 1? "male" : profile.gender === 2? "female" : "no specific gender",
|
|
335
258
|
type: profile.type || "User",
|
|
@@ -420,7 +343,6 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
420
343
|
|
|
421
344
|
module.exports._private = {
|
|
422
345
|
extractPhotoUrl,
|
|
423
|
-
extractCoverFromHTML,
|
|
424
346
|
normalizeUser
|
|
425
347
|
};
|
|
426
348
|
|
|
@@ -78,6 +78,7 @@ function createFallbackNamespaces(api) {
|
|
|
78
78
|
getID: bindOptionalMethod(api, "getUserID"),
|
|
79
79
|
getInfo: bindOptionalMethod(api, "getUserInfo"),
|
|
80
80
|
getInfoV2: bindOptionalMethod(api, "getUserInfoV2"),
|
|
81
|
+
getCoverPhoto: bindOptionalMethod(api, "getCoverPhoto"),
|
|
81
82
|
getFriends: bindOptionalMethod(api, "getFriendsList")
|
|
82
83
|
}),
|
|
83
84
|
account: compactNamespace({
|
|
@@ -89,6 +90,7 @@ function createFallbackNamespaces(api) {
|
|
|
89
90
|
enableAutoSaveAppState: bindOptionalMethod(api, "enableAutoSaveAppState"),
|
|
90
91
|
getCurrentUserID: bindOptionalMethod(api, "getCurrentUserID"),
|
|
91
92
|
handleFriendRequest: bindOptionalMethod(api, "handleFriendRequest"),
|
|
93
|
+
acceptFriendRequest: bindOptionalMethod(api, "acceptFriendRequest"),
|
|
92
94
|
logout: bindOptionalMethod(api, "logout"),
|
|
93
95
|
refreshDtsg: bindOptionalMethod(api, "refreshFb_dtsg"),
|
|
94
96
|
changeBlockedStatus: bindOptionalMethod(api, "changeBlockedStatus"),
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const logger = require("../../../func/logger");
|
|
4
|
+
const {
|
|
5
|
+
isSessionEnforcement,
|
|
6
|
+
createSessionEnforcementError,
|
|
7
|
+
isSessionEnforcementError
|
|
8
|
+
} = require("../sessionStatus");
|
|
4
9
|
|
|
5
10
|
/**
|
|
6
11
|
* Tạo hàm maybeAutoLogin: khi session hết hạn thì thử đăng nhập lại và retry request.
|
|
@@ -14,6 +19,22 @@ function createMaybeAutoLogin(ctx, http, helpers, emit, parseAndCheckLogin) {
|
|
|
14
19
|
const { buildUrl, headerOf, formatCookie } = helpers;
|
|
15
20
|
|
|
16
21
|
return async function maybeAutoLogin(resData, resConfig) {
|
|
22
|
+
const stopForEnforcement = () => {
|
|
23
|
+
const alreadyStopped = ctx._sessionEnforcement;
|
|
24
|
+
ctx._sessionEnforcement = true;
|
|
25
|
+
const error = createSessionEnforcementError();
|
|
26
|
+
if (!alreadyStopped) {
|
|
27
|
+
try {
|
|
28
|
+
emit("verificationRequired", { code: error.code, message: error.message });
|
|
29
|
+
} catch { }
|
|
30
|
+
}
|
|
31
|
+
return error;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
if (ctx._sessionEnforcement || isSessionEnforcement(resData) || isSessionEnforcement(resConfig)) {
|
|
35
|
+
throw stopForEnforcement();
|
|
36
|
+
}
|
|
37
|
+
|
|
17
38
|
const retryAfterLogin = async function () {
|
|
18
39
|
if (!resConfig) {
|
|
19
40
|
const e = new Error(
|
|
@@ -42,6 +63,9 @@ function createMaybeAutoLogin(ctx, http, helpers, emit, parseAndCheckLogin) {
|
|
|
42
63
|
}
|
|
43
64
|
return await parseAndCheckLogin(ctx, http)(newData);
|
|
44
65
|
} catch (retryErr) {
|
|
66
|
+
if (isSessionEnforcementError(retryErr) || isSessionEnforcement(retryErr)) {
|
|
67
|
+
throw stopForEnforcement();
|
|
68
|
+
}
|
|
45
69
|
if (
|
|
46
70
|
retryErr?.code === "ERR_INVALID_CHAR" ||
|
|
47
71
|
(retryErr?.message && retryErr.message.includes("Invalid character in header"))
|
|
@@ -79,6 +103,9 @@ function createMaybeAutoLogin(ctx, http, helpers, emit, parseAndCheckLogin) {
|
|
|
79
103
|
try {
|
|
80
104
|
ok = await ctx._autoLoginPromise;
|
|
81
105
|
} catch (autoLoginErr) {
|
|
106
|
+
if (isSessionEnforcementError(autoLoginErr) || isSessionEnforcement(autoLoginErr)) {
|
|
107
|
+
throw stopForEnforcement();
|
|
108
|
+
}
|
|
82
109
|
const e = new Error("Not logged in. Auto login failed.");
|
|
83
110
|
e.error = "Not logged in.";
|
|
84
111
|
e.res = resData;
|
|
@@ -122,6 +149,9 @@ function createMaybeAutoLogin(ctx, http, helpers, emit, parseAndCheckLogin) {
|
|
|
122
149
|
throw e;
|
|
123
150
|
}
|
|
124
151
|
} catch (autoLoginErr) {
|
|
152
|
+
if (isSessionEnforcementError(autoLoginErr) || isSessionEnforcement(autoLoginErr)) {
|
|
153
|
+
throw stopForEnforcement();
|
|
154
|
+
}
|
|
125
155
|
if (autoLoginErr.error === "Not logged in.") {
|
|
126
156
|
throw autoLoginErr;
|
|
127
157
|
}
|
|
@@ -4,15 +4,14 @@
|
|
|
4
4
|
* Outgoing-message pacing.
|
|
5
5
|
*
|
|
6
6
|
* Every outgoing message (MQTT, OldMessage and E2EE) is serialised through one queue and is
|
|
7
|
-
* released no sooner than `delay`
|
|
8
|
-
*
|
|
7
|
+
* released no sooner than a fixed `delay` after the previous one. The rolling cap limits bursts;
|
|
8
|
+
* send timing is not randomized to imitate a person.
|
|
9
9
|
*
|
|
10
10
|
* FCA_NX_SEND_DELAY_MS base gap between sends, default 2800 (set 0 to disable)
|
|
11
|
-
*
|
|
12
|
-
* or at runtime: api.setSendDelay(ms, jitterMs)
|
|
11
|
+
* or at runtime: setSendDelay(ms)
|
|
13
12
|
*/
|
|
14
13
|
|
|
15
|
-
const state = { last: 0, chain: Promise.resolve(), delay: null,
|
|
14
|
+
const state = { last: 0, chain: Promise.resolve(), delay: null, stamps: [] };
|
|
16
15
|
// Hard ceiling per rolling minute (FCA_NX_SEND_MAX_PER_MIN, default 8, 0 = off).
|
|
17
16
|
function maxPerMin() {
|
|
18
17
|
const n = Number(process.env.FCA_NX_SEND_MAX_PER_MIN);
|
|
@@ -27,14 +26,9 @@ function readNum(v, d) {
|
|
|
27
26
|
function getDelay() {
|
|
28
27
|
return state.delay != null ? state.delay : readNum(process.env.FCA_NX_SEND_DELAY_MS, 2800);
|
|
29
28
|
}
|
|
30
|
-
function
|
|
31
|
-
return state.jitter != null ? state.jitter : readNum(process.env.FCA_NX_SEND_JITTER_MS, 1400);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function setSendDelay(ms, jitterMs) {
|
|
29
|
+
function setSendDelay(ms) {
|
|
35
30
|
if (ms != null) state.delay = readNum(ms, 1000);
|
|
36
|
-
|
|
37
|
-
return { delay: getDelay(), jitter: getJitter() };
|
|
31
|
+
return { delay: getDelay(), jitter: 0 };
|
|
38
32
|
}
|
|
39
33
|
|
|
40
34
|
/** Resolves when it is this caller's turn to send. */
|
|
@@ -42,8 +36,7 @@ function waitTurn() {
|
|
|
42
36
|
const delay = getDelay();
|
|
43
37
|
if (delay <= 0) return Promise.resolve();
|
|
44
38
|
const turn = state.chain.then(async () => {
|
|
45
|
-
const
|
|
46
|
-
const wait = state.last + gap - Date.now();
|
|
39
|
+
const wait = state.last + delay - Date.now();
|
|
47
40
|
if (wait > 0) await new Promise(r => setTimeout(r, wait));
|
|
48
41
|
const cap = maxPerMin();
|
|
49
42
|
if (cap > 0) {
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Only explicit enforcement signals count. Ordinary page/chat text is not
|
|
4
|
+
// searched for general words such as "checkpoint" or "restricted".
|
|
5
|
+
const SESSION_ENFORCEMENT_REQUIRED = "SESSION_VERIFICATION_REQUIRED";
|
|
6
|
+
|
|
7
|
+
const CHECKPOINT_PAGE_MARKER =
|
|
8
|
+
/XCheckpointFBScrapingWarningController|\/checkpoint\/block\/|\/checkpoint\/\d{6,}/;
|
|
9
|
+
const CHECKPOINT_URL = /(?:facebook\.com)?\/checkpoint\/(?:\d|block|[?#]|$)/i;
|
|
10
|
+
const TRANSPORT_MARKER =
|
|
11
|
+
/(?:timed?\s*out|timeout|network error|socket hang up|connection reset|ECONNRESET|ECONNREFUSED|ENOTFOUND|ETIMEDOUT|EAI_AGAIN|EHOSTUNREACH|ENETUNREACH|ERR_NETWORK|UND_ERR_CONNECT_TIMEOUT)/i;
|
|
12
|
+
|
|
13
|
+
const URL_FIELDS = ["url", "redirect", "redirectUrl", "responseUrl", "responseURL", "location", "href"];
|
|
14
|
+
const ACCOUNT_STATUS_FIELD_MARKER =
|
|
15
|
+
/^\s*(?:your|this)\s+account\s+(?:is|has been|was)\s+(?:temporarily\s+)?(?:restricted|suspended|disabled|locked)\.?\s*$/i;
|
|
16
|
+
const CHECKPOINT_STATUS_FIELD_MARKER =
|
|
17
|
+
/^\s*checkpoint(?:\s+(?:verification|challenge))?\s+(?:is\s+)?(?:required|needed)\.?\s*$/i;
|
|
18
|
+
const CODE_FIELDS = ["code", "error", "name"];
|
|
19
|
+
const SUMMARY_FIELDS = [
|
|
20
|
+
"errorSummary",
|
|
21
|
+
"error_summary",
|
|
22
|
+
"errorDescription",
|
|
23
|
+
"error_description",
|
|
24
|
+
"errorMessage",
|
|
25
|
+
"error_message",
|
|
26
|
+
"error",
|
|
27
|
+
"reason"
|
|
28
|
+
];
|
|
29
|
+
const NESTED_FIELDS = [
|
|
30
|
+
"body",
|
|
31
|
+
"config",
|
|
32
|
+
"data",
|
|
33
|
+
"error",
|
|
34
|
+
"errors",
|
|
35
|
+
"originalResponse",
|
|
36
|
+
"payload",
|
|
37
|
+
"request",
|
|
38
|
+
"res",
|
|
39
|
+
"response"
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
function isCheckpointUrl(value) {
|
|
43
|
+
return typeof value === "string" && CHECKPOINT_URL.test(value);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function hasSignalFields(value, depth, seen) {
|
|
47
|
+
if (typeof value === "string") {
|
|
48
|
+
return CHECKPOINT_PAGE_MARKER.test(value) || isCheckpointUrl(value);
|
|
49
|
+
}
|
|
50
|
+
if (!value || typeof value !== "object" || depth > 5 || seen.has(value)) return false;
|
|
51
|
+
seen.add(value);
|
|
52
|
+
if (Array.isArray(value)) {
|
|
53
|
+
return value.slice(0, 20).some(entry => hasSignalFields(entry, depth + 1, seen));
|
|
54
|
+
}
|
|
55
|
+
if (value.requiresManualAction === true) return true;
|
|
56
|
+
for (const key of CODE_FIELDS) {
|
|
57
|
+
if (value[key] === SESSION_ENFORCEMENT_REQUIRED) return true;
|
|
58
|
+
}
|
|
59
|
+
for (const key of SUMMARY_FIELDS) {
|
|
60
|
+
if (
|
|
61
|
+
typeof value[key] === "string" &&
|
|
62
|
+
(CHECKPOINT_PAGE_MARKER.test(value[key]) || ACCOUNT_STATUS_FIELD_MARKER.test(value[key]) || CHECKPOINT_STATUS_FIELD_MARKER.test(value[key]))
|
|
63
|
+
) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (typeof value.message === "string" && CHECKPOINT_PAGE_MARKER.test(value.message)) return true;
|
|
68
|
+
for (const key of URL_FIELDS) {
|
|
69
|
+
if (isCheckpointUrl(value[key])) return true;
|
|
70
|
+
}
|
|
71
|
+
// Follow known response/error wrappers, not arbitrary application data.
|
|
72
|
+
for (const key of NESTED_FIELDS) {
|
|
73
|
+
if (hasSignalFields(value[key], depth + 1, seen)) return true;
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function isSessionEnforcement(value) {
|
|
79
|
+
return hasSignalFields(value, 0, new Set());
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function isTransientTransportError(value) {
|
|
83
|
+
if (isSessionEnforcement(value)) return false;
|
|
84
|
+
const text = typeof value === "string" ? value : value && (value.message || value.error || value.code) ? String(value.message || value.error || value.code) : "";
|
|
85
|
+
return TRANSPORT_MARKER.test(text);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function createSessionEnforcementError() {
|
|
89
|
+
const error = new Error(
|
|
90
|
+
"Facebook requires manual account review; automatic login and reconnect stopped. Resolve the notice with Facebook before restarting."
|
|
91
|
+
);
|
|
92
|
+
error.name = "SessionVerificationRequiredError";
|
|
93
|
+
error.code = SESSION_ENFORCEMENT_REQUIRED;
|
|
94
|
+
error.requiresManualAction = true;
|
|
95
|
+
return error;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function isSessionEnforcementError(value) {
|
|
99
|
+
return Boolean(
|
|
100
|
+
value &&
|
|
101
|
+
typeof value === "object" &&
|
|
102
|
+
(value.code === SESSION_ENFORCEMENT_REQUIRED || value.requiresManualAction === true || isSessionEnforcement(value))
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
module.exports = {
|
|
107
|
+
SESSION_ENFORCEMENT_REQUIRED,
|
|
108
|
+
isSessionEnforcement,
|
|
109
|
+
isTransientTransportError,
|
|
110
|
+
createSessionEnforcementError,
|
|
111
|
+
isSessionEnforcementError
|
|
112
|
+
};
|