@lazyneoaz/metachat 1.0.4 → 1.0.5
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/package.json +1 -1
- package/src/utils/clients.js +18 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lazyneoaz/metachat",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"types": "src/types/index.d.ts",
|
|
6
6
|
"description": "Advanced Facebook Chat API client for building Messenger bots — real-time messaging, thread management, MQTT, and session stability.",
|
package/src/utils/clients.js
CHANGED
|
@@ -197,7 +197,11 @@ function parseAndCheckLogin(ctx, http, retryCount = 0) {
|
|
|
197
197
|
log("Please verify your Facebook account status in a browser.");
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
-
|
|
200
|
+
// Only treat a redirect to login.php as a session expiry if the server
|
|
201
|
+
// explicitly told us to go there via res.redirect — not if login.php appears
|
|
202
|
+
// anywhere in the body JSON, which it does on authenticated pages as a
|
|
203
|
+
// navigation/share link, causing false-positive session expiry errors.
|
|
204
|
+
if (String(res.redirect || "").includes("login.php")) {
|
|
201
205
|
warn("Session Status", "Redirected to login page - Session expired");
|
|
202
206
|
const err = new Error("Session expired - Redirected to login page");
|
|
203
207
|
err.error = 401;
|
|
@@ -230,11 +234,19 @@ function saveCookies(jar) {
|
|
|
230
234
|
return function (res) {
|
|
231
235
|
const cookies = res.headers["set-cookie"] || [];
|
|
232
236
|
cookies.forEach(function (c) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
237
|
+
// Always attempt to save every Set-Cookie header to both domains.
|
|
238
|
+
// The old guard `c.indexOf(".facebook.com") > -1` silently dropped
|
|
239
|
+
// cookies whose domain attribute was `facebook.com` (no dot),
|
|
240
|
+
// `www.facebook.com`, or absent entirely. Facebook rotates critical
|
|
241
|
+
// session cookies (xs, c_user, fr, etc.) continuously — missing a
|
|
242
|
+
// single update causes the jar to go stale and Facebook forces logout.
|
|
243
|
+
try { jar.setCookie(c, "https://www.facebook.com"); } catch (_) {}
|
|
244
|
+
|
|
245
|
+
// Mirror to messenger.com so MQTT / Messenger API calls stay authed.
|
|
246
|
+
const c2 = c
|
|
247
|
+
.replace(/domain=[^;]*/i, "domain=.messenger.com")
|
|
248
|
+
.replace(/secure;?\s*/i, "");
|
|
249
|
+
try { jar.setCookie(c2, "https://www.messenger.com"); } catch (_) {}
|
|
238
250
|
});
|
|
239
251
|
return res;
|
|
240
252
|
};
|