@dongdev/fca-unofficial 2.0.30 → 2.0.31

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
@@ -125,3 +125,6 @@ Too lazy to write changelog, sorry! (will write changelog in the next release, t
125
125
 
126
126
  ## v2.0.29 - 2025-10-19
127
127
  - Hotfix / auto bump
128
+
129
+ ## v2.0.30 - 2025-10-19
130
+ - Hotfix / auto bump
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dongdev/fca-unofficial",
3
- "version": "2.0.30",
3
+ "version": "2.0.31",
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",
@@ -3,67 +3,44 @@
3
3
  const log = require("npmlog");
4
4
  const { getFrom } = require("../../utils/constants");
5
5
  const { get } = require("../../utils/request")
6
- module.exports = function(defaultFuncs, api, ctx) {
6
+ const { getType } = require("../../utils/format");
7
+ module.exports = function (defaultFuncs, api, ctx) {
7
8
  return function refreshFb_dtsg(obj, callback) {
8
- let resolveFunc, rejectFunc;
9
- const returnPromise = new Promise((resolve, reject) => {
10
- resolveFunc = resolve;
11
- rejectFunc = reject;
12
- });
13
- if (
14
- getType(obj) === "Function" ||
15
- getType(obj) === "AsyncFunction"
16
- ) {
9
+ if (typeof obj === "function") {
17
10
  callback = obj;
18
11
  obj = {};
19
12
  }
20
13
  if (!obj) obj = {};
21
14
  if (getType(obj) !== "Object") {
22
- throw Error(
23
- "The first parameter must be an object or a callback function"
24
- );
15
+ throw new CustomError("The first parameter must be an object or a callback function");
25
16
  }
17
+ let resolveFunc, rejectFunc;
18
+ const returnPromise = new Promise((resolve, reject) => {
19
+ resolveFunc = resolve;
20
+ rejectFunc = reject;
21
+ });
26
22
  if (!callback) {
27
- callback = (err, data) => (err ? rejectFunc(err) : resolveFunc(data));
23
+ callback = (err, data) => err ? rejectFunc(err) : resolveFunc(data);
28
24
  }
29
25
  if (Object.keys(obj).length === 0) {
30
- get(
31
- "https://www.facebook.com/",
32
- ctx.jar,
33
- null,
34
- ctx.globalOptions,
35
- {
36
- noRef: true
37
- }
38
- )
39
- .then(resData => {
40
- const fb_dtsg = getFrom(
41
- resData.body,
42
- '["DTSGInitData",[],{"token":"',
43
- '","'
44
- );
45
- const jazoest = getFrom(resData.body, "jazoest=", '",');
46
- if (!fb_dtsg) {
47
- throw Error(
48
- "Could not find fb_dtsg in HTML after requesting Facebook."
49
- );
50
- }
51
- ctx.fb_dtsg = fb_dtsg;
52
- ctx.jazoest = jazoest;
53
- callback(null, {
54
- data: { fb_dtsg, jazoest },
55
- message: "Refreshed fb_dtsg and jazoest"
56
- });
57
- })
58
- .catch(err => {
59
- log.error("refreshFb_dtsg", err);
60
- callback(err);
26
+ get("https://www.facebook.com/", ctx.jar, null, ctx.globalOptions, { noRef: true }).then(({ data }) => {
27
+ const fb_dtsg = getFrom(data, '["DTSGInitData",[],{"token":"', '","');
28
+ const jazoest = getFrom(data, "jazoest=", '",');
29
+ if (!fb_dtsg) throw new Error("Could not find fb_dtsg in HTML after requesting Facebook.");
30
+ Object.assign(ctx, { fb_dtsg, jazoest });
31
+ callback(null, {
32
+ data: { fb_dtsg, jazoest },
33
+ message: "Refreshed fb_dtsg and jazoest",
61
34
  });
35
+ }).catch(err => {
36
+ console.error("refreshFb_dtsg", err);
37
+ callback(err);
38
+ });
62
39
  } else {
63
40
  Object.assign(ctx, obj);
64
41
  callback(null, {
65
42
  data: obj,
66
- message: "Refreshed " + Object.keys(obj).join(", ")
43
+ message: `Refreshed ${Object.keys(obj).join(", ")}`,
67
44
  });
68
45
  }
69
46
  return returnPromise;