@dongdev/fca-unofficial 3.0.7 → 3.0.8

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
@@ -149,3 +149,6 @@ Too lazy to write changelog, sorry! (will write changelog in the next release, t
149
149
 
150
150
  ## v3.0.6 - 2025-11-27
151
151
  - Hotfix / auto bump
152
+
153
+ ## v3.0.7 - 2025-11-27
154
+ - Hotfix / auto bump
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dongdev/fca-unofficial",
3
- "version": "3.0.7",
3
+ "version": "3.0.8",
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",
@@ -226,14 +226,59 @@ module.exports = function(defaultFuncs, api, ctx) {
226
226
  .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
227
227
  .then(parseAndCheckLogin(ctx, defaultFuncs))
228
228
  .then(resData => {
229
- if (resData[resData.length - 1].error_results > 0)
230
- throw resData[0].o0.errors;
231
- if (resData[resData.length - 1].successful_results === 0)
229
+ // Validate resData is an array and has elements
230
+ if (!resData || !Array.isArray(resData) || resData.length === 0) {
231
+ throw {
232
+ error: "getThreadList: Invalid response data - resData is not a valid array",
233
+ res: resData
234
+ };
235
+ }
236
+
237
+ // Validate last element exists and has required properties
238
+ const lastElement = resData[resData.length - 1];
239
+ if (!lastElement || typeof lastElement !== "object") {
240
+ throw {
241
+ error: "getThreadList: Invalid response data - last element is missing or invalid",
242
+ res: resData
243
+ };
244
+ }
245
+
246
+ if (lastElement.error_results > 0) {
247
+ // Check if first element and o0 exist before accessing errors
248
+ if (resData[0] && resData[0].o0 && resData[0].o0.errors) {
249
+ throw resData[0].o0.errors;
250
+ } else {
251
+ throw {
252
+ error: "getThreadList: Error results > 0 but error details not available",
253
+ res: resData
254
+ };
255
+ }
256
+ }
257
+
258
+ if (lastElement.successful_results === 0) {
232
259
  throw {
233
260
  error: "getThreadList: there was no successful_results",
234
261
  res: resData
235
262
  };
236
- if (timestamp) resData[0].o0.data.viewer.message_threads.nodes.shift();
263
+ }
264
+
265
+ // Validate first element and nested data structure
266
+ if (!resData[0] || !resData[0].o0 || !resData[0].o0.data ||
267
+ !resData[0].o0.data.viewer || !resData[0].o0.data.viewer.message_threads ||
268
+ !Array.isArray(resData[0].o0.data.viewer.message_threads.nodes)) {
269
+ throw {
270
+ error: "getThreadList: Invalid response data structure - missing required fields",
271
+ res: resData
272
+ };
273
+ }
274
+
275
+ if (timestamp) {
276
+ const nodes = resData[0].o0.data.viewer.message_threads.nodes;
277
+ if (Array.isArray(nodes) && nodes.length > 0) {
278
+ nodes.shift();
279
+ }
280
+ }
281
+
237
282
  callback(
238
283
  null,
239
284
  formatThreadList(resData[0].o0.data.viewer.message_threads.nodes)