@dongdev/fca-unofficial 3.0.10 → 3.0.12

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/CHANGELOG.md CHANGED
@@ -158,3 +158,9 @@ Too lazy to write changelog, sorry! (will write changelog in the next release, t
158
158
 
159
159
  ## v3.0.9 - 2025-12-05
160
160
  - Hotfix / auto bump
161
+
162
+ ## v3.0.10 - 2025-12-05
163
+ - Hotfix / auto bump
164
+
165
+ ## v3.0.11 - 2025-12-05
166
+ - Hotfix / auto bump
@@ -281,13 +281,34 @@ function sort(obj) {
281
281
  async function setJarCookies(j, appstate) {
282
282
  const tasks = [];
283
283
  for (const c of appstate) {
284
- const dom = (c.domain || ".facebook.com").replace(/^\./, "");
285
- const path = c.path || "/";
286
- const base1 = `https://${dom}${path}`;
287
- const base2 = `https://www.${dom}${path}`;
288
- const str = `${c.key}=${c.value}; Domain=${c.domain || ".facebook.com"}; Path=${path};`;
289
- tasks.push(j.setCookie(str, base1));
290
- tasks.push(j.setCookie(str, base2));
284
+ const cookieName = c.name || c.key;
285
+ const cookieValue = c.value;
286
+ if (!cookieName || cookieValue === undefined) continue;
287
+
288
+ const cookieDomain = c.domain || ".facebook.com";
289
+ const cookiePath = c.path || "/";
290
+ const dom = cookieDomain.replace(/^\./, "");
291
+
292
+ // Format expires if provided
293
+ let expiresStr = "";
294
+ if (c.expires) {
295
+ const expiresDate = typeof c.expires === "number" ? new Date(c.expires) : new Date(c.expires);
296
+ expiresStr = `; expires=${expiresDate.toUTCString()}`;
297
+ }
298
+
299
+ // Build cookie string
300
+ const str = `${cookieName}=${cookieValue}${expiresStr}; Domain=${cookieDomain}; Path=${cookiePath};`;
301
+
302
+ // Set cookie for both http and https, with and without www
303
+ const base1 = `http://${dom}${cookiePath}`;
304
+ const base2 = `https://${dom}${cookiePath}`;
305
+ const base3 = `http://www.${dom}${cookiePath}`;
306
+ const base4 = `https://www.${dom}${cookiePath}`;
307
+
308
+ tasks.push(j.setCookie(str, base1).catch(() => { }));
309
+ tasks.push(j.setCookie(str, base2).catch(() => { }));
310
+ tasks.push(j.setCookie(str, base3).catch(() => { }));
311
+ tasks.push(j.setCookie(str, base4).catch(() => { }));
291
312
  }
292
313
  await Promise.all(tasks);
293
314
  }
@@ -570,41 +591,65 @@ function loginHelper(appState, Cookie, email, password, globalOptions, callback)
570
591
  return null;
571
592
  };
572
593
  let userIDFromAppState = extractUIDFromAppState(appState);
573
- try {
574
- if (appState) {
575
- if (typeof appState === "string") {
576
- let parsed = appState;
577
- try {
578
- parsed = JSON.parse(appState);
579
- } catch { }
580
- if (Array.isArray(parsed)) {
581
- const pairs = parsed.map(c => [c.name || c.key, c.value].join("="));
582
- setJarFromPairs(jar, pairs, domain);
583
- } else if (typeof parsed === "string") {
584
- const pairs = normalizeCookieHeaderString(parsed);
585
- if (!pairs.length) throw new Error("Empty appState cookie header");
586
- setJarFromPairs(jar, pairs, domain);
594
+ (async () => {
595
+ try {
596
+ if (appState) {
597
+ // Check and convert cookie to appState format
598
+ if (Array.isArray(appState) && appState.some(c => c.name)) {
599
+ // Convert name to key if needed
600
+ appState = appState.map(c => {
601
+ if (c.name && !c.key) {
602
+ c.key = c.name;
603
+ delete c.name;
604
+ }
605
+ return c;
606
+ });
607
+ } else if (typeof appState === "string") {
608
+ // Try to parse as JSON first
609
+ let parsed = appState;
610
+ try {
611
+ parsed = JSON.parse(appState);
612
+ } catch { }
613
+
614
+ if (Array.isArray(parsed)) {
615
+ // Already parsed as array, use it
616
+ appState = parsed;
617
+ } else {
618
+ // Parse string cookie format (key=value; key2=value2)
619
+ const arrayAppState = [];
620
+ appState.split(';').forEach(c => {
621
+ const [key, value] = c.split('=');
622
+ if (key && value) {
623
+ arrayAppState.push({
624
+ key: key.trim(),
625
+ value: value.trim(),
626
+ domain: ".facebook.com",
627
+ path: "/",
628
+ expires: new Date().getTime() + 1000 * 60 * 60 * 24 * 365
629
+ });
630
+ }
631
+ });
632
+ appState = arrayAppState;
633
+ }
634
+ }
635
+
636
+ // Set cookies into jar with individual domain/path
637
+ if (Array.isArray(appState)) {
638
+ await setJarCookies(jar, appState);
587
639
  } else {
588
640
  throw new Error("Invalid appState format");
589
641
  }
590
- } else if (Array.isArray(appState)) {
591
- const pairs = appState.map(c => [c.name || c.key, c.value].join("="));
592
- setJarFromPairs(jar, pairs, domain);
593
- } else {
594
- throw new Error("Invalid appState format");
595
642
  }
643
+ if (Cookie) {
644
+ let cookiePairs = [];
645
+ if (typeof Cookie === "string") cookiePairs = normalizeCookieHeaderString(Cookie);
646
+ else if (Array.isArray(Cookie)) cookiePairs = Cookie.map(String).filter(Boolean);
647
+ else if (Cookie && typeof Cookie === "object") cookiePairs = Object.entries(Cookie).map(([k, v]) => `${k}=${v}`);
648
+ if (cookiePairs.length) setJarFromPairs(jar, cookiePairs, domain);
649
+ }
650
+ } catch (e) {
651
+ return callback(e);
596
652
  }
597
- if (Cookie) {
598
- let cookiePairs = [];
599
- if (typeof Cookie === "string") cookiePairs = normalizeCookieHeaderString(Cookie);
600
- else if (Array.isArray(Cookie)) cookiePairs = Cookie.map(String).filter(Boolean);
601
- else if (Cookie && typeof Cookie === "object") cookiePairs = Object.entries(Cookie).map(([k, v]) => `${k}=${v}`);
602
- if (cookiePairs.length) setJarFromPairs(jar, cookiePairs, domain);
603
- }
604
- } catch (e) {
605
- return callback(e);
606
- }
607
- (async () => {
608
653
  const ctx = { globalOptions, options: globalOptions, reconnectAttempts: 0 };
609
654
  ctx.bypassAutomation = async function (resp, j) {
610
655
  global.fca = global.fca || {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dongdev/fca-unofficial",
3
- "version": "3.0.10",
3
+ "version": "3.0.12",
4
4
  "description": "Unofficial Facebook Chat API for Node.js - Interact with Facebook Messenger programmatically",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",