@dongdev/fca-unofficial 3.0.20 → 3.0.21

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
@@ -176,3 +176,6 @@ Too lazy to write changelog, sorry! (will write changelog in the next release, t
176
176
 
177
177
  ## v3.0.19 - 2025-12-31
178
178
  - Hotfix / auto bump
179
+
180
+ ## v3.0.20 - 2025-12-31
181
+ - Hotfix / auto bump
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dongdev/fca-unofficial",
3
- "version": "3.0.20",
3
+ "version": "3.0.21",
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",
@@ -1,49 +1,87 @@
1
1
  const { Sequelize } = require("sequelize");
2
2
  const fs = require("fs");
3
3
  const path = require("path");
4
- const databasePath = path.join(process.cwd(), "Fca_Database");
5
- if (!fs.existsSync(databasePath)) {
6
- fs.mkdirSync(databasePath, { recursive: true });
7
- }
8
- const sequelize = new Sequelize({
9
- dialect: "sqlite",
10
- storage: path.join(databasePath, "database.sqlite"),
11
- logging: false,
12
- pool: {
13
- max: 5,
14
- min: 0,
15
- acquire: 30000,
16
- idle: 10000
17
- },
18
- retry: {
19
- max: 3
20
- },
21
- dialectOptions: {
22
- timeout: 5000
23
- },
24
- isolationLevel: Sequelize.Transaction.ISOLATION_LEVELS.READ_COMMITTED
25
- });
26
- const models = {};
27
- fs.readdirSync(__dirname)
28
- .filter(file => file.endsWith(".js") && file !== "index.js")
29
- .forEach(file => {
30
- const model = require(path.join(__dirname, file))(sequelize);
31
- models[model.name] = model;
32
- });
33
- Object.keys(models).forEach(modelName => {
34
- if (models[modelName].associate) {
35
- models[modelName].associate(models);
4
+
5
+ let sequelize = null;
6
+ let models = {};
7
+
8
+ try {
9
+ const databasePath = path.join(process.cwd(), "Fca_Database");
10
+ if (!fs.existsSync(databasePath)) {
11
+ fs.mkdirSync(databasePath, { recursive: true });
36
12
  }
37
- });
38
- models.sequelize = sequelize;
39
- models.Sequelize = Sequelize;
40
- models.syncAll = async () => {
13
+
14
+ sequelize = new Sequelize({
15
+ dialect: "sqlite",
16
+ storage: path.join(databasePath, "database.sqlite"),
17
+ logging: false,
18
+ pool: {
19
+ max: 5,
20
+ min: 0,
21
+ acquire: 30000,
22
+ idle: 10000
23
+ },
24
+ retry: {
25
+ max: 3
26
+ },
27
+ dialectOptions: {
28
+ timeout: 5000
29
+ },
30
+ isolationLevel: Sequelize.Transaction.ISOLATION_LEVELS.READ_COMMITTED
31
+ });
32
+
33
+ // Load models with error handling
41
34
  try {
42
- await sequelize.sync({ force: false });
43
- } catch (error) {
44
- console.error("Failed to synchronize models:", error);
45
- throw error;
35
+ const modelFiles = fs.readdirSync(__dirname)
36
+ .filter(file => file.endsWith(".js") && file !== "index.js");
37
+
38
+ for (const file of modelFiles) {
39
+ try {
40
+ const model = require(path.join(__dirname, file))(sequelize);
41
+ if (model && model.name) {
42
+ models[model.name] = model;
43
+ }
44
+ } catch (modelError) {
45
+ // Log but continue loading other models
46
+ console.error(`Failed to load model ${file}:`, modelError && modelError.message ? modelError.message : String(modelError));
47
+ }
48
+ }
49
+
50
+ // Associate models
51
+ Object.keys(models).forEach(modelName => {
52
+ try {
53
+ if (models[modelName].associate) {
54
+ models[modelName].associate(models);
55
+ }
56
+ } catch (assocError) {
57
+ console.error(`Failed to associate model ${modelName}:`, assocError && assocError.message ? assocError.message : String(assocError));
58
+ }
59
+ });
60
+ } catch (loadError) {
61
+ console.error("Failed to load models:", loadError && loadError.message ? loadError.message : String(loadError));
46
62
  }
47
- };
63
+
64
+ models.sequelize = sequelize;
65
+ models.Sequelize = Sequelize;
66
+ models.syncAll = async () => {
67
+ try {
68
+ if (!sequelize) {
69
+ throw new Error("Sequelize instance not initialized");
70
+ }
71
+ await sequelize.sync({ force: false });
72
+ } catch (error) {
73
+ console.error("Failed to synchronize models:", error && error.message ? error.message : String(error));
74
+ throw error;
75
+ }
76
+ };
77
+ } catch (initError) {
78
+ // If initialization fails completely, still export a valid structure
79
+ console.error("Database initialization error:", initError && initError.message ? initError.message : String(initError));
80
+ models.sequelize = null;
81
+ models.Sequelize = Sequelize;
82
+ models.syncAll = async () => {
83
+ throw new Error("Database not initialized");
84
+ };
85
+ }
48
86
 
49
87
  module.exports = models;
@@ -17,8 +17,22 @@ module.exports = function(sequelize) {
17
17
  unique: true
18
18
  },
19
19
  data: {
20
- type: DataTypes.JSONB,
21
- allowNull: true
20
+ type: DataTypes.TEXT,
21
+ allowNull: true,
22
+ get() {
23
+ const value = this.getDataValue('data');
24
+ if (typeof value === 'string') {
25
+ try {
26
+ return JSON.parse(value);
27
+ } catch {
28
+ return value;
29
+ }
30
+ }
31
+ return value;
32
+ },
33
+ set(value) {
34
+ this.setDataValue('data', typeof value === 'string' ? value : JSON.stringify(value));
35
+ }
22
36
  }
23
37
  },
24
38
  {
@@ -17,8 +17,22 @@ module.exports = function (sequelize) {
17
17
  unique: true
18
18
  },
19
19
  data: {
20
- type: DataTypes.JSONB,
21
- allowNull: true
20
+ type: DataTypes.TEXT,
21
+ allowNull: true,
22
+ get() {
23
+ const value = this.getDataValue('data');
24
+ if (typeof value === 'string') {
25
+ try {
26
+ return JSON.parse(value);
27
+ } catch {
28
+ return value;
29
+ }
30
+ }
31
+ return value;
32
+ },
33
+ set(value) {
34
+ this.setDataValue('data', typeof value === 'string' ? value : JSON.stringify(value));
35
+ }
22
36
  }
23
37
  },
24
38
  {