@queenanya/baileys 8.2.5 → 8.2.6-beta

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.
@@ -38,7 +38,7 @@ class WebSocketClient extends types_1.AbstractSocketClient {
38
38
  headers: (_a = this.config.options) === null || _a === void 0 ? void 0 : _a.headers,
39
39
  handshakeTimeout: this.config.connectTimeoutMs,
40
40
  timeout: this.config.connectTimeoutMs,
41
- agent: this.config.agent,
41
+ agent: this.config.agent
42
42
  });
43
43
  this.socket.setMaxListeners(0);
44
44
  const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
@@ -112,7 +112,6 @@ const makeMessagesSocket = (config) => {
112
112
  };
113
113
  /** Fetch all the devices we've to send a message to */
114
114
  const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
115
- var _a;
116
115
  const deviceResults = [];
117
116
  if (!useCache) {
118
117
  logger.debug('not using cache for devices');
@@ -120,7 +119,12 @@ const makeMessagesSocket = (config) => {
120
119
  const toFetch = [];
121
120
  jids = Array.from(new Set(jids));
122
121
  for (let jid of jids) {
123
- const user = (_a = (0, WABinary_1.jidDecode)(jid)) === null || _a === void 0 ? void 0 : _a.user;
122
+ const decoded = (0, WABinary_1.jidDecode)(jid);
123
+ if (!decoded || !decoded.user) {
124
+ logger.warn(`Failed to decode or extract user from JID: ${jid}`);
125
+ continue; // skip if invalid
126
+ }
127
+ const user = decoded.user;
124
128
  jid = (0, WABinary_1.jidNormalizedUser)(jid);
125
129
  if (useCache) {
126
130
  const devices = userDevicesCache.get(user);
@@ -139,9 +143,7 @@ const makeMessagesSocket = (config) => {
139
143
  if (!toFetch.length) {
140
144
  return deviceResults;
141
145
  }
142
- const query = new WAUSync_1.USyncQuery()
143
- .withContext('message')
144
- .withDeviceProtocol();
146
+ const query = new WAUSync_1.USyncQuery().withContext('message').withDeviceProtocol();
145
147
  for (const jid of toFetch) {
146
148
  query.withUser(new WAUSync_1.USyncUser().withId(jid));
147
149
  }
@@ -6,7 +6,7 @@ const WABinary_1 = require("../WABinary");
6
6
  const socket_1 = require("./socket");
7
7
  const makeUSyncSocket = (config) => {
8
8
  const sock = (0, socket_1.makeSocket)(config);
9
- const { generateMessageTag, query, } = sock;
9
+ const { generateMessageTag, query } = sock;
10
10
  const executeUSyncQuery = async (usyncQuery) => {
11
11
  if (usyncQuery.protocols.length === 0) {
12
12
  throw new boom_1.Boom('USyncQuery must have at least one protocol');
@@ -14,15 +14,13 @@ const makeUSyncSocket = (config) => {
14
14
  // todo: validate users, throw WARNING on no valid users
15
15
  // variable below has only validated users
16
16
  const validUsers = usyncQuery.users;
17
- const userNodes = validUsers.map((user) => {
17
+ const userNodes = validUsers.map(user => {
18
18
  return {
19
19
  tag: 'user',
20
20
  attrs: {
21
- jid: !user.phone ? user.id : undefined,
21
+ jid: !user.phone ? user.id : undefined
22
22
  },
23
- content: usyncQuery.protocols
24
- .map((a) => a.getUserElement(user))
25
- .filter(a => a !== null)
23
+ content: usyncQuery.protocols.map(a => a.getUserElement(user)).filter(a => a !== null)
26
24
  };
27
25
  });
28
26
  const listNode = {
@@ -33,14 +31,14 @@ const makeUSyncSocket = (config) => {
33
31
  const queryNode = {
34
32
  tag: 'query',
35
33
  attrs: {},
36
- content: usyncQuery.protocols.map((a) => a.getQueryElement())
34
+ content: usyncQuery.protocols.map(a => a.getQueryElement())
37
35
  };
38
36
  const iq = {
39
37
  tag: 'iq',
40
38
  attrs: {
41
39
  to: WABinary_1.S_WHATSAPP_NET,
42
40
  type: 'get',
43
- xmlns: 'usync',
41
+ xmlns: 'usync'
44
42
  },
45
43
  content: [
46
44
  {
@@ -50,21 +48,18 @@ const makeUSyncSocket = (config) => {
50
48
  mode: usyncQuery.mode,
51
49
  sid: generateMessageTag(),
52
50
  last: 'true',
53
- index: '0',
51
+ index: '0'
54
52
  },
55
- content: [
56
- queryNode,
57
- listNode
58
- ]
53
+ content: [queryNode, listNode]
59
54
  }
60
- ],
55
+ ]
61
56
  };
62
57
  const result = await query(iq);
63
58
  return usyncQuery.parseUSyncQueryResult(result);
64
59
  };
65
60
  return {
66
61
  ...sock,
67
- executeUSyncQuery,
62
+ executeUSyncQuery
68
63
  };
69
64
  };
70
65
  exports.makeUSyncSocket = makeUSyncSocket;
@@ -9,7 +9,7 @@ class USyncContactProtocol {
9
9
  getQueryElement() {
10
10
  return {
11
11
  tag: 'contact',
12
- attrs: {},
12
+ attrs: {}
13
13
  };
14
14
  }
15
15
  getUserElement(user) {
@@ -17,7 +17,7 @@ class USyncContactProtocol {
17
17
  return {
18
18
  tag: 'contact',
19
19
  attrs: {},
20
- content: user.phone,
20
+ content: user.phone
21
21
  };
22
22
  }
23
23
  parser(node) {
@@ -10,8 +10,8 @@ class USyncDeviceProtocol {
10
10
  return {
11
11
  tag: 'devices',
12
12
  attrs: {
13
- version: '2',
14
- },
13
+ version: '2'
14
+ }
15
15
  };
16
16
  }
17
17
  getUserElement( /* user: USyncUser */) {
@@ -9,7 +9,7 @@ class USyncDisappearingModeProtocol {
9
9
  getQueryElement() {
10
10
  return {
11
11
  tag: 'disappearing_mode',
12
- attrs: {},
12
+ attrs: {}
13
13
  };
14
14
  }
15
15
  getUserElement() {
@@ -22,7 +22,7 @@ class USyncDisappearingModeProtocol {
22
22
  const setAt = new Date(+((node === null || node === void 0 ? void 0 : node.attrs.t) || 0) * 1000);
23
23
  return {
24
24
  duration,
25
- setAt,
25
+ setAt
26
26
  };
27
27
  }
28
28
  }
@@ -9,7 +9,7 @@ class USyncStatusProtocol {
9
9
  getQueryElement() {
10
10
  return {
11
11
  tag: 'status',
12
- attrs: {},
12
+ attrs: {}
13
13
  };
14
14
  }
15
15
  getUserElement() {
@@ -34,7 +34,7 @@ class USyncStatusProtocol {
34
34
  }
35
35
  return {
36
36
  status,
37
- setAt,
37
+ setAt
38
38
  };
39
39
  }
40
40
  }
@@ -17,7 +17,7 @@ class USyncBotProfileProtocol {
17
17
  return {
18
18
  tag: 'bot',
19
19
  attrs: {},
20
- content: [{ tag: 'profile', attrs: { 'persona_id': user.personaId } }]
20
+ content: [{ tag: 'profile', attrs: { persona_id: user.personaId } }]
21
21
  };
22
22
  }
23
23
  parser(node) {
@@ -8,7 +8,7 @@ class USyncLIDProtocol {
8
8
  getQueryElement() {
9
9
  return {
10
10
  tag: 'lid',
11
- attrs: {},
11
+ attrs: {}
12
12
  };
13
13
  }
14
14
  getUserElement() {
@@ -28,13 +28,13 @@ class USyncQuery {
28
28
  if (result.attrs.type !== 'result') {
29
29
  return;
30
30
  }
31
- const protocolMap = Object.fromEntries(this.protocols.map((protocol) => {
31
+ const protocolMap = Object.fromEntries(this.protocols.map(protocol => {
32
32
  return [protocol.name, protocol.parser];
33
33
  }));
34
34
  const queryResult = {
35
35
  // TODO: implement errors etc.
36
36
  list: [],
37
- sideList: [],
37
+ sideList: []
38
38
  };
39
39
  const usyncNode = (0, WABinary_1.getBinaryNodeChild)(result, 'usync');
40
40
  //TODO: implement error backoff, refresh etc.
@@ -42,18 +42,22 @@ class USyncQuery {
42
42
  //const resultNode = getBinaryNodeChild(usyncNode, 'result')
43
43
  const listNode = (0, WABinary_1.getBinaryNodeChild)(usyncNode, 'list');
44
44
  if (Array.isArray(listNode === null || listNode === void 0 ? void 0 : listNode.content) && typeof listNode !== 'undefined') {
45
- queryResult.list = listNode.content.map((node) => {
45
+ queryResult.list = listNode.content.map(node => {
46
46
  const id = node === null || node === void 0 ? void 0 : node.attrs.jid;
47
- const data = Array.isArray(node === null || node === void 0 ? void 0 : node.content) ? Object.fromEntries(node.content.map((content) => {
48
- const protocol = content.tag;
49
- const parser = protocolMap[protocol];
50
- if (parser) {
51
- return [protocol, parser(content)];
52
- }
53
- else {
54
- return [protocol, null];
55
- }
56
- }).filter(([, b]) => b !== null)) : {};
47
+ const data = Array.isArray(node === null || node === void 0 ? void 0 : node.content)
48
+ ? Object.fromEntries(node.content
49
+ .map(content => {
50
+ const protocol = content.tag;
51
+ const parser = protocolMap[protocol];
52
+ if (parser) {
53
+ return [protocol, parser(content)];
54
+ }
55
+ else {
56
+ return [protocol, null];
57
+ }
58
+ })
59
+ .filter(([, b]) => b !== null))
60
+ : {};
57
61
  return { ...data, id };
58
62
  });
59
63
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@queenanya/baileys",
3
- "version": "8.2.5",
3
+ "version": "8.2.6-beta",
4
4
  "description": "Custom Baileys WhatsApp API",
5
5
  "keywords": [
6
6
  "baileys",
@@ -29,6 +29,23 @@
29
29
  "WASignalGroup/*.js",
30
30
  "engine-requirements.js"
31
31
  ],
32
+ "scripts": {
33
+ "build:all": "tsc && typedoc",
34
+ "build:docs": "typedoc",
35
+ "build:tsc": "tsc",
36
+ "changelog:last": "conventional-changelog -p angular -r 2",
37
+ "changelog:preview": "conventional-changelog -p angular -u",
38
+ "changelog:update": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
39
+ "example": "node --inspect -r ts-node/register Example/example.ts",
40
+ "gen:protobuf": "sh WAProto/GenerateStatics.sh",
41
+ "lint": "eslint src --ext .js,.ts",
42
+ "lint:fix": "yarn lint --fix",
43
+ "prepack": "tsc",
44
+ "prepare": "tsc",
45
+ "preinstall": "node ./engine-requirements.js",
46
+ "release": "release-it",
47
+ "test": "jest"
48
+ },
32
49
  "dependencies": {
33
50
  "@adiwajshing/keyed-db": "^0.2.4",
34
51
  "@cacheable/node-cache": "^1.4.0",
@@ -87,20 +104,5 @@
87
104
  "sharp": {
88
105
  "optional": true
89
106
  }
90
- },
91
- "scripts": {
92
- "build:all": "tsc && typedoc",
93
- "build:docs": "typedoc",
94
- "build:tsc": "tsc",
95
- "changelog:last": "conventional-changelog -p angular -r 2",
96
- "changelog:preview": "conventional-changelog -p angular -u",
97
- "changelog:update": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
98
- "example": "node --inspect -r ts-node/register Example/example.ts",
99
- "gen:protobuf": "sh WAProto/GenerateStatics.sh",
100
- "lint": "eslint src --ext .js,.ts",
101
- "lint:fix": "yarn lint --fix",
102
- "preinstall": "node ./engine-requirements.js",
103
- "release": "release-it",
104
- "test": "jest"
105
107
  }
106
- }
108
+ }