@rexxhayanasi/elaina-baileys 1.0.8 → 1.1.0-rc.1

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.
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useSQLiteAuth = void 0;
7
+ const sqlite_1 = __importDefault(require("./sqlite"));
8
+ exports.useSQLiteAuth = sqlite_1.default;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.useSQLiteAuth = void 0;
5
+
6
+ const better_sqlite3_1 = require("better-sqlite3");
7
+ const baileys_1 = require("../index");
8
+
9
+ const BetterSqlite = better_sqlite3_1.default || better_sqlite3_1;
10
+ const db = new BetterSqlite("./session.db");
11
+
12
+ db.exec(`
13
+ CREATE TABLE IF NOT EXISTS auth (
14
+ id TEXT PRIMARY KEY,
15
+ data TEXT
16
+ )
17
+ `);
18
+
19
+ const useSQLiteAuth = () => {
20
+ const readData = (id) => {
21
+ const row = db.prepare("SELECT data FROM auth WHERE id=?").get(id);
22
+ return row ? JSON.parse(row.data, baileys_1.BufferJSON.reviver) : null;
23
+ };
24
+
25
+ const writeData = (id, data) => {
26
+ db.prepare("INSERT OR REPLACE INTO auth VALUES (?, ?)")
27
+ .run(id, JSON.stringify(data, baileys_1.BufferJSON.replacer));
28
+ };
29
+
30
+ const state = {
31
+ creds: readData("creds") || {},
32
+ keys: {
33
+ get(type, ids) {
34
+ const data = {};
35
+ for (const id of ids) {
36
+ const v = readData(`${type}-${id}`);
37
+ if (v)
38
+ data[id] = v;
39
+ }
40
+ return data;
41
+ },
42
+ set(data) {
43
+ for (const type in data) {
44
+ for (const id in data[type]) {
45
+ writeData(`${type}-${id}`, data[type][id]);
46
+ }
47
+ }
48
+ }
49
+ }
50
+ };
51
+
52
+ const saveCreds = () => writeData("creds", state.creds);
53
+
54
+ return { state, saveCreds };
55
+ };
56
+
57
+ exports.useSQLiteAuth = useSQLiteAuth;
58
+ exports.default = useSQLiteAuth;
@@ -3,6 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+
7
+ const PHONENUMBER_MCC = require("./phonenumber_mcc.json");
8
+ exports.PHONENUMBER_MCC = PHONENUMBER_MCC;
9
+
6
10
  exports.DEFAULT_CACHE_TTLS = exports.MIN_UPLOAD_INTERVAL = exports.UPLOAD_TIMEOUT = exports.INITIAL_PREKEY_COUNT = exports.MIN_PREKEY_COUNT = exports.MEDIA_KEYS = exports.MEDIA_HKDF_KEY_MAPPING = exports.MEDIA_PATH_MAP = exports.DEFAULT_CONNECTION_CONFIG = exports.PROCESSABLE_HISTORY_TYPES = exports.WA_CERT_DETAILS = exports.URL_REGEX = exports.NOISE_WA_HEADER = exports.KEY_BUNDLE_TYPE = exports.DICT_VERSION = exports.NOISE_MODE = exports.WA_DEFAULT_EPHEMERAL = exports.WA_ADV_HOSTED_DEVICE_SIG_PREFIX = exports.WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX = exports.WA_ADV_DEVICE_SIG_PREFIX = exports.WA_ADV_ACCOUNT_SIG_PREFIX = exports.UNAUTHORIZED_CODES = exports.version = void 0;
7
11
  const WAProto_1 = require("../../WAProto");
8
12
  const libsignal_1 = require("../Signal/libsignal");
@@ -115,4 +119,4 @@ exports.DEFAULT_CACHE_TTLS = {
115
119
  MSG_RETRY: 60 * 60,
116
120
  CALL_OFFER: 5 * 60,
117
121
  USER_DEVICES: 5 * 60
118
- };
122
+ };
@@ -0,0 +1,223 @@
1
+ {
2
+ "93": 412,
3
+ "355": 276,
4
+ "213": 603,
5
+ "1-684": 544,
6
+ "376": 213,
7
+ "244": 631,
8
+ "1-264": 365,
9
+ "1-268": 344,
10
+ "54": 722,
11
+ "374": 283,
12
+ "297": 363,
13
+ "61": 505,
14
+ "43": 232,
15
+ "994": 400,
16
+ "1-242": 364,
17
+ "973": 426,
18
+ "880": 470,
19
+ "1-246": 342,
20
+ "375": 257,
21
+ "32": 206,
22
+ "501": 702,
23
+ "229": 616,
24
+ "1-441": 350,
25
+ "975": 402,
26
+ "591": 736,
27
+ "387": 218,
28
+ "267": 652,
29
+ "55": 724,
30
+ "1-284": 348,
31
+ "673": 528,
32
+ "359": 284,
33
+ "226": 613,
34
+ "257": 642,
35
+ "855": 456,
36
+ "237": 624,
37
+ "238": 625,
38
+ "1-345": 346,
39
+ "236": 623,
40
+ "235": 622,
41
+ "56": 730,
42
+ "86": 454,
43
+ "57": 732,
44
+ "269": 654,
45
+ "682": 548,
46
+ "506": 712,
47
+ "385": 219,
48
+ "53": 368,
49
+ "357": 280,
50
+ "420": 230,
51
+ "243": 630,
52
+ "45": 238,
53
+ "253": 638,
54
+ "1-767": 366,
55
+ "1-809": 370,
56
+ "1-849": 370,
57
+ "1-829": 370,
58
+ "593": 740,
59
+ "20": 602,
60
+ "503": 706,
61
+ "240": 627,
62
+ "291": 657,
63
+ "372": 248,
64
+ "251": 636,
65
+ "500": 750,
66
+ "298": 288,
67
+ "679": 542,
68
+ "358": 244,
69
+ "33": 208,
70
+ "689": 547,
71
+ "241": 628,
72
+ "220": 607,
73
+ "995": 282,
74
+ "49": 262,
75
+ "233": 620,
76
+ "350": 266,
77
+ "30": 202,
78
+ "299": 290,
79
+ "1-473": 352,
80
+ "1-671": 535,
81
+ "502": 704,
82
+ "224": 537,
83
+ "592": 738,
84
+ "509": 372,
85
+ "504": 708,
86
+ "852": 454,
87
+ "36": 216,
88
+ "354": 274,
89
+ "91": 404,
90
+ "62": 510,
91
+ "98": 432,
92
+ "964": 418,
93
+ "353": 234,
94
+ "972": 425,
95
+ "39": 222,
96
+ "225": 612,
97
+ "1-876": 338,
98
+ "81": 440,
99
+ "962": 416,
100
+ "254": 639,
101
+ "686": 545,
102
+ "383": 221,
103
+ "965": 419,
104
+ "371": 247,
105
+ "961": 415,
106
+ "266": 651,
107
+ "231": 618,
108
+ "218": 606,
109
+ "423": 295,
110
+ "370": 246,
111
+ "352": 270,
112
+ "389": 294,
113
+ "261": 646,
114
+ "265": 650,
115
+ "60": 502,
116
+ "960": 472,
117
+ "223": 610,
118
+ "356": 278,
119
+ "692": 551,
120
+ "222": 609,
121
+ "230": 617,
122
+ "52": 334,
123
+ "691": 550,
124
+ "373": 259,
125
+ "377": 212,
126
+ "976": 428,
127
+ "382": 297,
128
+ "1-664": 354,
129
+ "212": 604,
130
+ "258": 643,
131
+ "95": 414,
132
+ "264": 649,
133
+ "674": 536,
134
+ "977": 429,
135
+ "31": 204,
136
+ "687": 546,
137
+ "64": 530,
138
+ "505": 710,
139
+ "227": 614,
140
+ "234": 621,
141
+ "683": 555,
142
+ "1-670": 534,
143
+ "47": 242,
144
+ "968": 226,
145
+ "92": 410,
146
+ "680": 552,
147
+ "970": 423,
148
+ "507": 714,
149
+ "675": 537,
150
+ "595": 744,
151
+ "51": 716,
152
+ "63": 515,
153
+ "48": 260,
154
+ "351": 268,
155
+ "1-787, 1-939": 330,
156
+ "974": 427,
157
+ "242": 630,
158
+ "40": 226,
159
+ "7": 250,
160
+ "250": 635,
161
+ "290": 658,
162
+ "1-869": 356,
163
+ "1-758": 358,
164
+ "508": 308,
165
+ "1-784": 360,
166
+ "685": 544,
167
+ "378": 292,
168
+ "239": 626,
169
+ "966": 420,
170
+ "221": 608,
171
+ "381": 220,
172
+ "248": 633,
173
+ "232": 619,
174
+ "65": 525,
175
+ "386": 293,
176
+ "677": 540,
177
+ "27": 655,
178
+ "211": 659,
179
+ "34": 214,
180
+ "94": 413,
181
+ "249": 634,
182
+ "597": 746,
183
+ "268": 653,
184
+ "46": 240,
185
+ "41": 228,
186
+ "963": 417,
187
+ "886": 466,
188
+ "992": 436,
189
+ "255": 640,
190
+ "66": 520,
191
+ "228": 615,
192
+ "690": 554,
193
+ "676": 539,
194
+ "1-868": 374,
195
+ "216": 605,
196
+ "90": 286,
197
+ "993": 438,
198
+ "1-649": 376,
199
+ "688": 553,
200
+ "1-340": 332,
201
+ "256": 641,
202
+ "380": 255,
203
+ "971": 424,
204
+ "44": 234,
205
+ "1": 310,
206
+ "598": 748,
207
+ "998": 434,
208
+ "678": 541,
209
+ "379": 225,
210
+ "58": 734,
211
+ "681": 543,
212
+ "967": 421,
213
+ "260": 645,
214
+ "263": 648,
215
+ "670": 514,
216
+ "245": 632,
217
+ "856": 457,
218
+ "599": 362,
219
+ "850": 467,
220
+ "262": 647,
221
+ "82": 450,
222
+ "84": 452
223
+ }
@@ -6,7 +6,12 @@ const WABinary_1 = require("../WABinary");
6
6
  const generic_utils_1 = require("../WABinary/generic-utils");
7
7
  const messages_recv_1 = require("./messages-recv");
8
8
  const makeBusinessSocket = (config) => {
9
- const sock = (0, messages_recv_1.makeMessagesRecvSocket)(config);
9
+ const sock = (0, messages_recv_1.makeMessagesRecvSocket)({
10
+ ...config,
11
+ forceNewConnection: true,
12
+ syncFullHistory: false,
13
+ shouldIgnoreJid: () => false
14
+ });
10
15
  const { authState, query, waUploadToServer } = sock;
11
16
  const getCatalog = async ({ jid, limit, cursor }) => {
12
17
  var _a;
@@ -1,10 +1,36 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const Defaults_1 = require("../Defaults");
4
- const business_1 = require("./business");
5
- // export the last socket layer
6
- const makeWASocket = (config) => ((0, business_1.makeBusinessSocket)({
7
- ...Defaults_1.DEFAULT_CONNECTION_CONFIG,
1
+ "use strict"
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true })
4
+
5
+ const { DEFAULT_CONNECTION_CONFIG } = require("../Defaults")
6
+ const { makeBusinessSocket } = require("./business")
7
+
8
+ let __ACTIVE_SOCKET__ = null
9
+
10
+ const makeWASocket = (config) => {
11
+ try {
12
+ if (__ACTIVE_SOCKET__) {
13
+ try {
14
+ __ACTIVE_SOCKET__.ev?.removeAllListeners?.()
15
+ __ACTIVE_SOCKET__.ws?.removeAllListeners?.()
16
+ __ACTIVE_SOCKET__.ws?.terminate?.()
17
+ __ACTIVE_SOCKET__.ws?.close?.()
18
+ } catch {}
19
+
20
+ try {
21
+ __ACTIVE_SOCKET__ = null
22
+ } catch {}
23
+ }
24
+ } catch {}
25
+
26
+ const sock = makeBusinessSocket({
27
+ ...DEFAULT_CONNECTION_CONFIG,
8
28
  ...config
9
- }));
10
- exports.default = makeWASocket;
29
+ })
30
+
31
+ __ACTIVE_SOCKET__ = sock
32
+
33
+ return sock
34
+ }
35
+
36
+ exports.default = makeWASocket
@@ -261,34 +261,46 @@ const makeSocket = (config) => {
261
261
  }
262
262
  });
263
263
  };
264
- const end = (error) => {
265
- if (closed) {
266
- logger.trace({ trace: error === null || error === void 0 ? void 0 : error.stack }, 'connection already closed');
267
- return;
268
- }
269
- closed = true;
270
- logger.info({ trace: error === null || error === void 0 ? void 0 : error.stack }, error ? 'connection errored' : 'connection closed');
271
- clearInterval(keepAliveReq);
272
- clearTimeout(qrTimer);
273
- ws.removeAllListeners('close');
274
- ws.removeAllListeners('error');
275
- ws.removeAllListeners('open');
276
- ws.removeAllListeners('message');
277
- if (!ws.isClosed && !ws.isClosing) {
278
- try {
279
- ws.close();
280
- }
281
- catch (_a) { }
282
- }
264
+ const end = (error) => {
265
+ if (closed) return
266
+ closed = true
267
+
268
+ try { clearInterval(keepAliveReq) } catch {}
269
+ try { clearTimeout(qrTimer) } catch {}
270
+
271
+ try {
272
+ ws.off('message', onMessageReceived)
273
+ ws.removeAllListeners?.()
274
+ } catch {}
275
+
276
+ try {
277
+ if (ws.terminate) {
278
+ ws.terminate()
279
+ } else {
280
+ ws.close()
281
+ }
282
+ } catch {}
283
+
284
+ try {
283
285
  ev.emit('connection.update', {
284
286
  connection: 'close',
285
287
  lastDisconnect: {
286
288
  error,
287
289
  date: new Date()
288
290
  }
289
- });
290
- ev.removeAllListeners('connection.update');
291
- };
291
+ })
292
+ } catch {}
293
+
294
+ try { ev.flush?.() } catch {}
295
+ try { ev.removeAllListeners?.() } catch {}
296
+
297
+ try {
298
+ if (authState?.creds?.isConnecting) {
299
+ authState.creds.isConnecting = false
300
+ ev.emit?.('creds.update', authState.creds)
301
+ }
302
+ } catch {}
303
+ };
292
304
  const waitForSocketOpen = async () => {
293
305
  if (ws.isOpen) {
294
306
  return;
package/lib/index.js CHANGED
@@ -53,5 +53,6 @@ __exportStar(require("./WABinary"), exports);
53
53
  __exportStar(require("./WAM"), exports);
54
54
  __exportStar(require("./WAUSync"), exports);
55
55
  __exportStar(require("./Api"), exports);
56
+ __exportStar(require("./Auth"), exports);
56
57
 
57
58
  exports.default = Socket_1.default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rexxhayanasi/elaina-baileys",
3
- "version": "1.0.8",
3
+ "version": "1.1.0-rc.1",
4
4
  "description": "Custom Baileys WhatsApp API",
5
5
  "keywords": [
6
6
  "baileys",
@@ -47,6 +47,7 @@
47
47
  "@hapi/boom": "^9.1.3",
48
48
  "async-mutex": "^0.5.0",
49
49
  "axios": "^1.6.0",
50
+ "better-sqlite3": "^12.5.0",
50
51
  "chalk": "^4.1.2",
51
52
  "gradient-string": "^2.0.2",
52
53
  "cache-manager": "^5.7.6",
@@ -70,7 +71,7 @@
70
71
  "conventional-changelog-cli": "^2.2.2",
71
72
  "eslint": "^8.0.0",
72
73
  "jest": "^27.0.6",
73
- "jimp": "^0.16.1",
74
+ "jimp": "^1.6.0",
74
75
  "json": "^11.0.0",
75
76
  "link-preview-js": "^3.0.0",
76
77
  "open": "^8.4.2",
@@ -84,7 +85,7 @@
84
85
  },
85
86
  "peerDependencies": {
86
87
  "audio-decode": "^2.1.3",
87
- "jimp": "^0.16.1",
88
+ "jimp": "^1.6.0",
88
89
  "link-preview-js": "^3.0.0",
89
90
  "qrcode-terminal": "^0.12.0",
90
91
  "sharp": "^0.34.1"