@dongdev/fca-unofficial 2.0.21 → 2.0.22

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
@@ -98,3 +98,6 @@ Too lazy to write changelog, sorry! (will write changelog in the next release, t
98
98
 
99
99
  ## v2.0.20 - 2025-10-08
100
100
  - Hotfix / auto bump
101
+
102
+ ## v2.0.21 - 2025-10-08
103
+ - Hotfix / auto bump
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dongdev/fca-unofficial",
3
- "version": "2.0.21",
3
+ "version": "2.0.22",
4
4
  "description": "Unofficial Facebook Chat API for Node.js - Interact with Facebook Messenger programmatically",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,64 +1,46 @@
1
1
  "use strict";
2
2
 
3
- const log = require("npmlog");
4
- const { get } = require("../../utils/request");
5
- const { getType } = require("../../utils/format");
6
- module.exports = function(defaultFuncs, api, ctx) {
7
- return function httpGet(url, form, customHeader, callback, notAPI) {
8
- let resolveFunc = function() {};
9
- let rejectFunc = function() {};
3
+ const { getType } = require("../../utils/format.js");
4
+ const { get } = require("../../utils/request.js");
10
5
 
11
- const returnPromise = new Promise(function(resolve, reject) {
6
+ const httpGetFactory = function (defaultFuncs, api, ctx) {
7
+ return function httpGet(url, form, callback, notAPI) {
8
+ let resolveFunc = () => { };
9
+ let rejectFunc = () => { };
10
+
11
+ const returnPromise = new Promise((resolve, reject) => {
12
12
  resolveFunc = resolve;
13
13
  rejectFunc = reject;
14
14
  });
15
15
 
16
16
  if (
17
- getType(form) == "Function" ||
18
- getType(form) == "AsyncFunction"
17
+ !callback &&
18
+ (getType(form) === "Function" || getType(form) === "AsyncFunction")
19
19
  ) {
20
20
  callback = form;
21
21
  form = {};
22
22
  }
23
23
 
24
- if (
25
- getType(customHeader) == "Function" ||
26
- getType(customHeader) == "AsyncFunction"
27
- ) {
28
- callback = customHeader;
29
- customHeader = {};
30
- }
31
-
32
- customHeader = customHeader || {};
24
+ form = form || {};
33
25
 
34
26
  callback =
35
27
  callback ||
36
- function(err, data) {
28
+ function (err, data) {
37
29
  if (err) return rejectFunc(err);
38
30
  resolveFunc(data);
39
31
  };
40
32
 
41
- if (notAPI) {
42
- get(url, ctx.jar, form, ctx.globalOptions, ctx, customHeader)
43
- .then(function(resData) {
44
- callback(null, resData.data.toString());
45
- })
46
- .catch(function(err) {
47
- log.error("httpGet", err);
48
- return callback(err);
49
- });
50
- } else {
51
- defaultFuncs
52
- .get(url, ctx.jar, form, null, customHeader)
53
- .then(function(resData) {
54
- callback(null, resData.data.toString());
55
- })
56
- .catch(function(err) {
57
- log.error("httpGet", err);
58
- return callback(err);
59
- });
60
- }
33
+ const executor = notAPI ? get : defaultFuncs.get;
34
+
35
+ executor(url, ctx.jar, form)
36
+ .then((resData) => callback(null, resData.data))
37
+ .catch(function (err) {
38
+ console.error("httpGet", err);
39
+ return callback(err);
40
+ });
61
41
 
62
42
  return returnPromise;
63
43
  };
64
44
  };
45
+
46
+ module.exports = httpGetFactory;
@@ -1,64 +1,52 @@
1
1
  "use strict";
2
2
 
3
- const log = require("npmlog");
4
3
  const { post } = require("../../utils/request");
5
4
  const { getType } = require("../../utils/format");
6
- module.exports = function(defaultFuncs, api, ctx) {
7
- return function httpPost(url, form, customHeader, callback, notAPI) {
8
- let resolveFunc = function() {};
9
- let rejectFunc = function() {};
10
5
 
11
- const returnPromise = new Promise(function(resolve, reject) {
6
+ const httpPostFactory = function (defaultFuncs, api, ctx) {
7
+ return function httpPost(url, form, callback, notAPI) {
8
+ let resolveFunc = () => { };
9
+ let rejectFunc = () => { };
10
+
11
+ const returnPromise = new Promise((resolve, reject) => {
12
12
  resolveFunc = resolve;
13
13
  rejectFunc = reject;
14
14
  });
15
15
 
16
16
  if (
17
- getType(form) == "Function" ||
18
- getType(form) == "AsyncFunction"
17
+ !callback &&
18
+ (getType(form) === "Function" || getType(form) === "AsyncFunction")
19
19
  ) {
20
20
  callback = form;
21
21
  form = {};
22
22
  }
23
23
 
24
- if (
25
- getType(customHeader) == "Function" ||
26
- getType(customHeader) == "AsyncFunction"
27
- ) {
28
- callback = customHeader;
29
- customHeader = {};
30
- }
31
-
32
- customHeader = customHeader || {};
24
+ form = form || {};
33
25
 
34
26
  callback =
35
27
  callback ||
36
- function(err, data) {
28
+ function (err, data) {
37
29
  if (err) return rejectFunc(err);
38
30
  resolveFunc(data);
39
31
  };
40
32
 
41
- if (notAPI) {
42
- post(url, ctx.jar, form, ctx.globalOptions, ctx, customHeader)
43
- .then(function(resData) {
44
- callback(null, resData.data.toString());
45
- })
46
- .catch(function(err) {
47
- log.error("httpPost", err);
48
- return callback(err);
49
- });
50
- } else {
51
- defaultFuncs
52
- .post(url, ctx.jar, form, {}, customHeader)
53
- .then(function(resData) {
54
- callback(null, resData.data.toString());
55
- })
56
- .catch(function(err) {
57
- log.error("httpPost", err);
58
- return callback(err);
59
- });
60
- }
33
+ const executor = notAPI ? post : defaultFuncs.post;
34
+
35
+ executor(url, ctx.jar, form, ctx.globalOptions)
36
+ .then((resData) => {
37
+ let data = resData.data;
38
+ if (typeof data === "object") {
39
+ data = JSON.stringify(data, null, 2);
40
+ }
41
+ callback(null, data);
42
+ })
43
+ .catch((err) => {
44
+ console.error("httpPost", err);
45
+ return callback(err);
46
+ });
61
47
 
62
48
  return returnPromise;
63
49
  };
64
50
  };
51
+
52
+ module.exports = httpPostFactory;