@dongdev/fca-unofficial 3.0.19 → 3.0.20

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
@@ -173,3 +173,6 @@ Too lazy to write changelog, sorry! (will write changelog in the next release, t
173
173
 
174
174
  ## v3.0.17 - 2025-12-16
175
175
  - Hotfix / auto bump
176
+
177
+ ## v3.0.19 - 2025-12-31
178
+ - Hotfix / auto bump
package/module/login.js CHANGED
@@ -20,6 +20,11 @@ if (!global.fca._errorHandlersInstalled) {
20
20
  const errorCode = reason.code || reason.cause?.code;
21
21
  const errorMessage = reason.message || String(reason);
22
22
 
23
+ // Suppress Sequelize instance errors (handled gracefully in getBackupModel)
24
+ if (errorMessage.includes("No Sequelize instance passed")) {
25
+ return; // Silently ignore - already handled
26
+ }
27
+
23
28
  // Handle fetch timeout errors gracefully
24
29
  if (errorCode === "UND_ERR_CONNECT_TIMEOUT" ||
25
30
  errorCode === "ETIMEDOUT" ||
@@ -54,6 +59,11 @@ if (!global.fca._errorHandlersInstalled) {
54
59
  const errorMessage = error.message || String(error);
55
60
  const errorCode = error.code;
56
61
 
62
+ // Suppress Sequelize instance errors (handled gracefully in getBackupModel)
63
+ if (errorMessage.includes("No Sequelize instance passed")) {
64
+ return; // Silently ignore - already handled
65
+ }
66
+
57
67
  // Handle fetch/network errors
58
68
  if (errorCode === "UND_ERR_CONNECT_TIMEOUT" ||
59
69
  errorCode === "ETIMEDOUT" ||
@@ -182,28 +182,45 @@ function cookieHeaderFromJar(j) {
182
182
  let uniqueIndexEnsured = false;
183
183
 
184
184
  function getBackupModel() {
185
- if (!models || !models.sequelize || !models.Sequelize) return null;
186
- const sequelize = models.sequelize;
187
- const { DataTypes } = models.Sequelize;
188
- if (sequelize.models && sequelize.models.AppStateBackup) return sequelize.models.AppStateBackup;
189
- const dialect = typeof sequelize.getDialect === "function" ? sequelize.getDialect() : "sqlite";
190
- const LongText = (dialect === "mysql" || dialect === "mariadb") ? DataTypes.TEXT("long") : DataTypes.TEXT;
191
- const AppStateBackup = sequelize.define(
192
- "AppStateBackup",
193
- {
194
- id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
195
- userID: { type: DataTypes.STRING, allowNull: false },
196
- type: { type: DataTypes.STRING, allowNull: false },
197
- data: { type: LongText }
198
- },
199
- { tableName: "app_state_backups", timestamps: true, indexes: [{ unique: true, fields: ["userID", "type"] }] }
200
- );
201
- return AppStateBackup;
185
+ try {
186
+ if (!models || !models.sequelize || !models.Sequelize) return null;
187
+ const sequelize = models.sequelize;
188
+
189
+ // Validate that sequelize is a proper Sequelize instance
190
+ if (!sequelize || typeof sequelize.define !== "function") return null;
191
+
192
+ const { DataTypes } = models.Sequelize;
193
+ if (sequelize.models && sequelize.models.AppStateBackup) return sequelize.models.AppStateBackup;
194
+ const dialect = typeof sequelize.getDialect === "function" ? sequelize.getDialect() : "sqlite";
195
+ const LongText = (dialect === "mysql" || dialect === "mariadb") ? DataTypes.TEXT("long") : DataTypes.TEXT;
196
+
197
+ try {
198
+ const AppStateBackup = sequelize.define(
199
+ "AppStateBackup",
200
+ {
201
+ id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
202
+ userID: { type: DataTypes.STRING, allowNull: false },
203
+ type: { type: DataTypes.STRING, allowNull: false },
204
+ data: { type: LongText }
205
+ },
206
+ { tableName: "app_state_backups", timestamps: true, indexes: [{ unique: true, fields: ["userID", "type"] }] }
207
+ );
208
+ return AppStateBackup;
209
+ } catch (defineError) {
210
+ // If define fails, log and return null
211
+ logger(`Failed to define AppStateBackup model: ${defineError && defineError.message ? defineError.message : String(defineError)}`, "warn");
212
+ return null;
213
+ }
214
+ } catch (e) {
215
+ // Silently handle any errors in getBackupModel
216
+ return null;
217
+ }
202
218
  }
203
219
 
204
220
  async function ensureUniqueIndex(sequelize) {
205
- if (uniqueIndexEnsured) return;
221
+ if (uniqueIndexEnsured || !sequelize) return;
206
222
  try {
223
+ if (typeof sequelize.getQueryInterface !== "function") return;
207
224
  await sequelize.getQueryInterface().addIndex("app_state_backups", ["userID", "type"], { unique: true, name: "app_state_user_type_unique" });
208
225
  } catch { }
209
226
  uniqueIndexEnsured = true;
@@ -225,6 +242,7 @@ async function backupAppStateSQL(j, userID) {
225
242
  try {
226
243
  const Model = getBackupModel();
227
244
  if (!Model) return;
245
+ if (!models || !models.sequelize) return;
228
246
  await Model.sync();
229
247
  await ensureUniqueIndex(models.sequelize);
230
248
  const appJson = getAppState(j);
@@ -910,8 +928,12 @@ function loginHelper(appState, Cookie, email, password, globalOptions, callback)
910
928
  }
911
929
  })
912
930
  .catch(function (error) {
913
- console.error(error);
914
- console.error("Database connection failed:", error && error.message ? error.message : String(error));
931
+ // Silently handle database errors - they're not critical for login
932
+ const errorMsg = error && error.message ? error.message : String(error);
933
+ if (!errorMsg.includes("No Sequelize instance passed")) {
934
+ // Only log non-Sequelize instance errors
935
+ logger(`Database connection failed: ${errorMsg}`, "warn");
936
+ }
915
937
  });
916
938
  logger("FCA fix/update by DongDev (Donix-VN)", "info");
917
939
  const ctxMain = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dongdev/fca-unofficial",
3
- "version": "3.0.19",
3
+ "version": "3.0.20",
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",
@@ -61,7 +61,6 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
61
61
  }
62
62
  defaultFuncs.post = postSafe;
63
63
  ctx._postGuarded = true;
64
- logger("postSafe guard installed for defaultFuncs.post", "info");
65
64
  return postSafe;
66
65
  }
67
66