@ellxz24/baileys 2.0.29 → 2.0.31

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.
@@ -5,6 +5,10 @@ exports.makeLIDMappingStore = void 0;
5
5
  const WABinary_1 = require("../WABinary");
6
6
  const lru_cache_1 = require("lru-cache");
7
7
 
8
+ const isHostedPnUser = (jid) => {
9
+ const decoded = (0, WABinary_1.jidDecode)(jid);
10
+ return decoded ? decoded.server === 'hosted' : false;
11
+ };
8
12
  const makeLIDMappingStore = (keys, logger, pnToLIDFunc) => {
9
13
  const mappingCache = new lru_cache_1.LRUCache({
10
14
  ttl: 7 * 24 * 60 * 60 * 1000,
@@ -62,7 +66,8 @@ const makeLIDMappingStore = (keys, logger, pnToLIDFunc) => {
62
66
  const successfulPairs = {};
63
67
 
64
68
  for (const pn of pns) {
65
- if (!(0, WABinary_1.isPnUser)(pn) && !(0, WABinary_1.isHostedPnUser)(pn)) continue;
69
+ // MENGGUNAKAN FALLBACK isHostedPnUser
70
+ if (!(0, WABinary_1.isPnUser)(pn) && !isHostedPnUser(pn)) continue;
66
71
  const decoded = (0, WABinary_1.jidDecode)(pn);
67
72
  if (!decoded) continue;
68
73
  const pnUser = decoded.user;
@@ -78,7 +83,9 @@ const makeLIDMappingStore = (keys, logger, pnToLIDFunc) => {
78
83
  logger && logger.trace(`No LID mapping found for PN user ${pnUser}; batch getting from USync`);
79
84
  const device = decoded.device || 0;
80
85
  let normalizedPn = (0, WABinary_1.jidNormalizedUser)(pn);
81
- if ((0, WABinary_1.isHostedPnUser)(normalizedPn)) {
86
+
87
+ // MENGGUNAKAN FALLBACK isHostedPnUser
88
+ if (isHostedPnUser(normalizedPn)) {
82
89
  normalizedPn = `${pnUser}@s.whatsapp.net`;
83
90
  }
84
91
  if (!usyncFetch[normalizedPn]) {
@@ -1,73 +1,63 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LIDMappingStore = void 0;
3
+ exports.makeLIDMappingStore = void 0;
4
4
 
5
5
  const WABinary_1 = require("../WABinary");
6
6
  const lru_cache_1 = require("lru-cache");
7
7
 
8
- class LIDMappingStore {
9
- constructor(keys, logger, pnToLIDFunc) {
10
- this.mappingCache = new lru_cache_1.LRUCache({
11
- ttl: 7 * 24 * 60 * 60 * 1000,
12
- ttlAutopurge: true,
13
- updateAgeOnGet: true
14
- });
15
- this.keys = keys;
16
- this.pnToLIDFunc = pnToLIDFunc;
17
- this.logger = logger;
18
- }
8
+ const makeLIDMappingStore = (keys, logger, pnToLIDFunc) => {
9
+ const mappingCache = new lru_cache_1.LRUCache({
10
+ ttl: 7 * 24 * 60 * 60 * 1000,
11
+ ttlAutopurge: true,
12
+ updateAgeOnGet: true
13
+ });
19
14
 
20
- async storeLIDPNMappings(pairs) {
15
+ const storeLIDPNMappings = async (pairs) => {
21
16
  const pairMap = {};
22
17
  for (const { lid, pn } of pairs) {
23
18
  if (!(((0, WABinary_1.isLidUser)(lid) && (0, WABinary_1.isPnUser)(pn)) || ((0, WABinary_1.isPnUser)(lid) && (0, WABinary_1.isLidUser)(pn)))) {
24
- this.logger.warn(`Invalid LID-PN mapping: ${lid}, ${pn}`);
19
+ logger && logger.warn(`Invalid LID-PN mapping: ${lid}, ${pn}`);
25
20
  continue;
26
21
  }
27
22
  const lidDecoded = (0, WABinary_1.jidDecode)(lid);
28
23
  const pnDecoded = (0, WABinary_1.jidDecode)(pn);
29
- if (!lidDecoded || !pnDecoded) return;
24
+ if (!lidDecoded || !pnDecoded) continue;
30
25
  const pnUser = pnDecoded.user;
31
26
  const lidUser = lidDecoded.user;
32
27
 
33
- let existingLidUser = this.mappingCache.get(`pn:${pnUser}`);
28
+ let existingLidUser = mappingCache.get(`pn:${pnUser}`);
34
29
  if (!existingLidUser) {
35
- this.logger.trace(`Cache miss for PN user ${pnUser}; checking database`);
36
- const stored = await this.keys.get("lid-mapping", [pnUser]);
30
+ logger && logger.trace(`Cache miss for PN user ${pnUser}; checking database`);
31
+ const stored = await keys.get("lid-mapping", [pnUser]);
37
32
  existingLidUser = stored[pnUser];
38
33
  if (existingLidUser) {
39
- this.mappingCache.set(`pn:${pnUser}`, existingLidUser);
40
- this.mappingCache.set(`lid:${existingLidUser}`, pnUser);
34
+ mappingCache.set(`pn:${pnUser}`, existingLidUser);
35
+ mappingCache.set(`lid:${existingLidUser}`, pnUser);
41
36
  }
42
37
  }
43
38
  if (existingLidUser === lidUser) {
44
- this.logger.debug({ pnUser, lidUser }, "LID mapping already exists, skipping");
39
+ logger && logger.debug({ pnUser, lidUser }, "LID mapping already exists, skipping");
45
40
  continue;
46
41
  }
47
42
  pairMap[pnUser] = lidUser;
48
43
  }
49
44
 
50
- this.logger.trace({ pairMap }, `Storing ${Object.keys(pairMap).length} pn mappings`);
51
- await this.keys.transaction(async () => {
45
+ logger && logger.trace({ pairMap }, `Storing ${Object.keys(pairMap).length} pn mappings`);
46
+ await keys.transaction(async () => {
52
47
  for (const [pnUser, lidUser] of Object.entries(pairMap)) {
53
- await this.keys.set({
48
+ await keys.set({
54
49
  "lid-mapping": {
55
50
  [pnUser]: lidUser,
56
51
  [`${lidUser}_reverse`]: pnUser
57
52
  }
58
53
  });
59
- this.mappingCache.set(`pn:${pnUser}`, lidUser);
60
- this.mappingCache.set(`lid:${lidUser}`, pnUser);
54
+ mappingCache.set(`pn:${pnUser}`, lidUser);
55
+ mappingCache.set(`lid:${lidUser}`, pnUser);
61
56
  }
62
57
  }, "lid-mapping");
63
- }
58
+ };
64
59
 
65
- async getLIDForPN(pn) {
66
- const result = await this.getLIDsForPNs([pn]);
67
- return result?.[0]?.lid || null;
68
- }
69
-
70
- async getLIDsForPNs(pns) {
60
+ const getLIDsForPNs = async (pns) => {
71
61
  const usyncFetch = {};
72
62
  const successfulPairs = {};
73
63
 
@@ -77,15 +67,15 @@ class LIDMappingStore {
77
67
  if (!decoded) continue;
78
68
  const pnUser = decoded.user;
79
69
 
80
- let lidUser = this.mappingCache.get(`pn:${pnUser}`);
70
+ let lidUser = mappingCache.get(`pn:${pnUser}`);
81
71
  if (!lidUser) {
82
- const stored = await this.keys.get("lid-mapping", [pnUser]);
72
+ const stored = await keys.get("lid-mapping", [pnUser]);
83
73
  lidUser = stored[pnUser];
84
74
  if (lidUser) {
85
- this.mappingCache.set(`pn:${pnUser}`, lidUser);
86
- this.mappingCache.set(`lid:${lidUser}`, pnUser);
75
+ mappingCache.set(`pn:${pnUser}`, lidUser);
76
+ mappingCache.set(`lid:${lidUser}`, pnUser);
87
77
  } else {
88
- this.logger.trace(`No LID mapping found for PN user ${pnUser}; batch getting from USync`);
78
+ logger && logger.trace(`No LID mapping found for PN user ${pnUser}; batch getting from USync`);
89
79
  const device = decoded.device || 0;
90
80
  let normalizedPn = (0, WABinary_1.jidNormalizedUser)(pn);
91
81
  if ((0, WABinary_1.isHostedPnUser)(normalizedPn)) {
@@ -102,19 +92,19 @@ class LIDMappingStore {
102
92
 
103
93
  lidUser = lidUser.toString();
104
94
  if (!lidUser) {
105
- this.logger.warn(`Invalid or empty LID user for PN ${pn}: lidUser = "${lidUser}"`);
95
+ logger && logger.warn(`Invalid or empty LID user for PN ${pn}: lidUser = "${lidUser}"`);
106
96
  return null;
107
97
  }
108
98
  const pnDevice = decoded.device !== undefined ? decoded.device : 0;
109
99
  const deviceSpecificLid = `${lidUser}${!!pnDevice ? `:${pnDevice}` : ``}@${decoded.server === "hosted" ? "hosted.lid" : "lid"}`;
110
- this.logger.trace(`getLIDForPN: ${pn} → ${deviceSpecificLid} (user mapping with device ${pnDevice})`);
100
+ logger && logger.trace(`getLIDForPN: ${pn} → ${deviceSpecificLid} (user mapping with device ${pnDevice})`);
111
101
  successfulPairs[pn] = { lid: deviceSpecificLid, pn };
112
102
  }
113
103
 
114
104
  if (Object.keys(usyncFetch).length > 0) {
115
- const result = await this.pnToLIDFunc?.(Object.keys(usyncFetch));
105
+ const result = await pnToLIDFunc?.(Object.keys(usyncFetch));
116
106
  if (result && result.length > 0) {
117
- this.storeLIDPNMappings(result);
107
+ await storeLIDPNMappings(result);
118
108
  for (const pair of result) {
119
109
  const pnDecoded = (0, WABinary_1.jidDecode)(pair.pn);
120
110
  const pnUser = pnDecoded?.user;
@@ -124,7 +114,7 @@ class LIDMappingStore {
124
114
 
125
115
  for (const device of usyncFetch[pair.pn]) {
126
116
  const deviceSpecificLid = `${lidUser}${!!device ? `:${device}` : ``}@${device === 99 ? "hosted.lid" : "lid"}`;
127
- this.logger.trace(`getLIDForPN: USYNC success for ${pair.pn} → ${deviceSpecificLid} (user mapping with device ${device})`);
117
+ logger && logger.trace(`getLIDForPN: USYNC success for ${pair.pn} → ${deviceSpecificLid} (user mapping with device ${device})`);
128
118
  const deviceSpecificPn = `${pnUser}${!!device ? `:${device}` : ``}@${device === 99 ? "hosted" : "s.whatsapp.net"}`;
129
119
  successfulPairs[deviceSpecificPn] = { lid: deviceSpecificLid, pn: deviceSpecificPn };
130
120
  }
@@ -134,30 +124,43 @@ class LIDMappingStore {
134
124
  }
135
125
  }
136
126
  return Object.values(successfulPairs);
137
- }
127
+ };
138
128
 
139
- async getPNForLID(lid) {
129
+ const getLIDForPN = async (pn) => {
130
+ const result = await getLIDsForPNs([pn]);
131
+ return result?.[0]?.lid || null;
132
+ };
133
+
134
+ const getPNForLID = async (lid) => {
140
135
  if (!(0, WABinary_1.isLidUser)(lid)) return null;
141
136
  const decoded = (0, WABinary_1.jidDecode)(lid);
142
137
  if (!decoded) return null;
143
138
 
144
139
  const lidUser = decoded.user;
145
- let pnUser = this.mappingCache.get(`lid:${lidUser}`);
140
+ let pnUser = mappingCache.get(`lid:${lidUser}`);
146
141
 
147
142
  if (!pnUser || typeof pnUser !== "string") {
148
- const stored = await this.keys.get("lid-mapping", [`${lidUser}_reverse`]);
143
+ const stored = await keys.get("lid-mapping", [`${lidUser}_reverse`]);
149
144
  pnUser = stored[`${lidUser}_reverse`];
150
145
  if (!pnUser || typeof pnUser !== "string") {
151
- this.logger.trace(`No reverse mapping found for LID user: ${lidUser}`);
146
+ logger && logger.trace(`No reverse mapping found for LID user: ${lidUser}`);
152
147
  return null;
153
148
  }
154
- this.mappingCache.set(`lid:${lidUser}`, pnUser);
149
+ mappingCache.set(`lid:${lidUser}`, pnUser);
155
150
  }
156
151
 
157
152
  const lidDevice = decoded.device !== undefined ? decoded.device : 0;
158
153
  const pnJid = `${pnUser}:${lidDevice}@${decoded.domainType === WABinary_1.WAJIDDomains.HOSTED_LID ? "hosted" : "s.whatsapp.net"}`;
159
- this.logger.trace(`Found reverse mapping: ${lid} → ${pnJid}`);
154
+ logger && logger.trace(`Found reverse mapping: ${lid} → ${pnJid}`);
160
155
  return pnJid;
161
- }
162
- }
163
- exports.LIDMappingStore = LIDMappingStore;
156
+ };
157
+
158
+ return {
159
+ mappingCache,
160
+ storeLIDPNMappings,
161
+ getLIDForPN,
162
+ getLIDsForPNs,
163
+ getPNForLID
164
+ };
165
+ };
166
+ exports.makeLIDMappingStore = makeLIDMappingStore;
@@ -1,62 +1,128 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jidNormalizedUser = exports.isJidNewsLetter = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
4
- exports.S_WHATSAPP_NET = '@s.whatsapp.net';
5
- exports.OFFICIAL_BIZ_JID = '16505361212@c.us';
6
- exports.SERVER_JID = 'server@c.us';
7
- exports.PSA_WID = '0@c.us';
8
- exports.STORIES_JID = 'status@broadcast';
3
+ exports.transferDevice = exports.jidNormalizedUser = exports.isJidBot = exports.isHostedLidUser = exports.isHostedPnUser = exports.isJidNewsletter = exports.isJidNewsLetter = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isPnUser = exports.isJidUser = exports.isJidMetaAI = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.getServerFromDomainType = exports.WAJIDDomains = exports.PSA_WID = exports.SERVER_JID = exports.META_AI_JID = exports.STORIES_JID = exports.S_WHATSAPP_NET = exports.OFFICIAL_BIZ_JID = void 0;
4
+
5
+ exports.OFFICIAL_BIZ_JID = "16505361212@c.us";
6
+ exports.S_WHATSAPP_NET = "@s.whatsapp.net";
7
+ exports.STORIES_JID = "status@broadcast";
8
+ exports.META_AI_JID = "13135550002@c.us";
9
+ exports.SERVER_JID = "server@c.us";
10
+ exports.PSA_WID = "0@c.us";
11
+
12
+ var WAJIDDomains;
13
+ (function (WAJIDDomains) {
14
+ WAJIDDomains[WAJIDDomains["WHATSAPP"] = 0] = "WHATSAPP";
15
+ WAJIDDomains[WAJIDDomains["LID"] = 1] = "LID";
16
+ WAJIDDomains[WAJIDDomains["HOSTED"] = 128] = "HOSTED";
17
+ WAJIDDomains[WAJIDDomains["HOSTED_LID"] = 129] = "HOSTED_LID";
18
+ })(WAJIDDomains || (exports.WAJIDDomains = WAJIDDomains = {}));
19
+
20
+ const getServerFromDomainType = (initialServer, domainType) => {
21
+ switch (domainType) {
22
+ case WAJIDDomains.LID:
23
+ return "lid";
24
+ case WAJIDDomains.HOSTED:
25
+ return "hosted";
26
+ case WAJIDDomains.HOSTED_LID:
27
+ return "hosted.lid";
28
+ case WAJIDDomains.WHATSAPP:
29
+ default:
30
+ return initialServer;
31
+ }
32
+ };
33
+ exports.getServerFromDomainType = getServerFromDomainType;
34
+
9
35
  const jidEncode = (user, server, device, agent) => {
10
- return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server}`;
36
+ return `${user || ""}${!!agent ? `_${agent}` : ""}${!!device ? `:${device}` : ""}@${server}`;
11
37
  };
12
38
  exports.jidEncode = jidEncode;
39
+
13
40
  const jidDecode = (jid) => {
14
- const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;
15
- if (sepIdx < 0) {
16
- return undefined;
17
- }
18
- const server = jid.slice(sepIdx + 1);
19
- const userCombined = jid.slice(0, sepIdx);
20
- const [userAgent, device] = userCombined.split(':');
21
- const user = userAgent.split('_')[0];
22
- return {
23
- server,
24
- user,
25
- domainType: server === 'lid' ? 1 : 0,
26
- device: device ? +device : undefined
27
- };
41
+ const sepIdx = typeof jid === "string" ? jid.indexOf("@") : -1;
42
+ if (sepIdx < 0) {
43
+ return undefined;
44
+ }
45
+ const server = jid.slice(sepIdx + 1);
46
+ const userCombined = jid.slice(0, sepIdx);
47
+ const [userAgent, device] = userCombined.split(":");
48
+ const [user, agent] = userAgent.split("_");
49
+ let domainType = WAJIDDomains.WHATSAPP;
50
+ if (server === "lid") {
51
+ domainType = WAJIDDomains.LID;
52
+ }
53
+ else if (server === "hosted") {
54
+ domainType = WAJIDDomains.HOSTED;
55
+ }
56
+ else if (server === "hosted.lid") {
57
+ domainType = WAJIDDomains.HOSTED_LID;
58
+ }
59
+ else if (agent) {
60
+ domainType = parseInt(agent);
61
+ }
62
+ return {
63
+ server: server,
64
+ user: user,
65
+ domainType,
66
+ device: device ? +device : undefined
67
+ };
28
68
  };
29
69
  exports.jidDecode = jidDecode;
30
- /** is the jid a user */
70
+
31
71
  const areJidsSameUser = (jid1, jid2) => {
32
72
  var _a, _b;
33
73
  return (((_a = (0, exports.jidDecode)(jid1)) === null || _a === void 0 ? void 0 : _a.user) === ((_b = (0, exports.jidDecode)(jid2)) === null || _b === void 0 ? void 0 : _b.user));
34
74
  };
35
75
  exports.areJidsSameUser = areJidsSameUser;
36
- /** is the jid a user */
37
- const isJidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@s.whatsapp.net'));
76
+
77
+ const isJidMetaAI = (jid) => jid === null || jid === void 0 ? void 0 : jid.endsWith("@bot");
78
+ exports.isJidMetaAI = isJidMetaAI;
79
+
80
+ const isJidUser = (jid) => jid === null || jid === void 0 ? void 0 : jid.endsWith("@s.whatsapp.net");
38
81
  exports.isJidUser = isJidUser;
39
- /** is the jid a group */
40
- const isLidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@lid'));
82
+
83
+ const isPnUser = (jid) => jid === null || jid === void 0 ? void 0 : jid.endsWith("@s.whatsapp.net");
84
+ exports.isPnUser = isPnUser;
85
+
86
+ const isLidUser = (jid) => jid === null || jid === void 0 ? void 0 : jid.endsWith("@lid");
41
87
  exports.isLidUser = isLidUser;
42
- /** is the jid a broadcast */
43
- const isJidBroadcast = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@broadcast'));
88
+
89
+ const isJidBroadcast = (jid) => jid === null || jid === void 0 ? void 0 : jid.endsWith("@broadcast");
44
90
  exports.isJidBroadcast = isJidBroadcast;
45
- /** is the jid a group */
46
- const isJidGroup = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@g.us'));
91
+
92
+ const isJidGroup = (jid) => jid === null || jid === void 0 ? void 0 : jid.endsWith("@g.us");
47
93
  exports.isJidGroup = isJidGroup;
48
- /** is the jid the status broadcast */
49
- const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
94
+
95
+ const isJidStatusBroadcast = (jid) => jid === "status@broadcast";
50
96
  exports.isJidStatusBroadcast = isJidStatusBroadcast;
51
- /** is the jid the newsletter */
52
- const isJidNewsLetter = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('newsletter'));
53
- exports.isJidNewsLetter = isJidNewsLetter;
97
+
98
+ const isJidNewsletter = (jid) => jid === null || jid === void 0 ? void 0 : jid.endsWith("@newsletter");
99
+ exports.isJidNewsletter = isJidNewsletter;
100
+ exports.isJidNewsLetter = isJidNewsletter;
101
+
102
+ const isHostedPnUser = (jid) => jid === null || jid === void 0 ? void 0 : jid.endsWith("@hosted");
103
+ exports.isHostedPnUser = isHostedPnUser;
104
+
105
+ const isHostedLidUser = (jid) => jid === null || jid === void 0 ? void 0 : jid.endsWith("@hosted.lid");
106
+ exports.isHostedLidUser = isHostedLidUser;
107
+
108
+ const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/;
109
+ const isJidBot = (jid) => jid && botRegexp.test(jid.split("@")[0]) && jid.endsWith("@c.us");
110
+ exports.isJidBot = isJidBot;
111
+
54
112
  const jidNormalizedUser = (jid) => {
55
- const result = (0, exports.jidDecode)(jid);
56
- if (!result) {
57
- return '';
58
- }
59
- const { user, server } = result;
60
- return (0, exports.jidEncode)(user, server === 'c.us' ? 's.whatsapp.net' : server);
113
+ const result = (0, exports.jidDecode)(jid);
114
+ if (!result) {
115
+ return "";
116
+ }
117
+ const { user, server } = result;
118
+ return (0, exports.jidEncode)(user, server === "c.us" ? "s.whatsapp.net" : server);
61
119
  };
62
120
  exports.jidNormalizedUser = jidNormalizedUser;
121
+
122
+ const transferDevice = (fromJid, toJid) => {
123
+ const fromDecoded = (0, exports.jidDecode)(fromJid);
124
+ const deviceId = (fromDecoded === null || fromDecoded === void 0 ? void 0 : fromDecoded.device) || 0;
125
+ const { server, user } = (0, exports.jidDecode)(toJid);
126
+ return (0, exports.jidEncode)(user, server, deviceId);
127
+ };
128
+ exports.transferDevice = transferDevice;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.jidNormalizedUser = exports.isJidNewsLetter = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
4
+ exports.S_WHATSAPP_NET = '@s.whatsapp.net';
5
+ exports.OFFICIAL_BIZ_JID = '16505361212@c.us';
6
+ exports.SERVER_JID = 'server@c.us';
7
+ exports.PSA_WID = '0@c.us';
8
+ exports.STORIES_JID = 'status@broadcast';
9
+ const jidEncode = (user, server, device, agent) => {
10
+ return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server}`;
11
+ };
12
+ exports.jidEncode = jidEncode;
13
+ const jidDecode = (jid) => {
14
+ const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;
15
+ if (sepIdx < 0) {
16
+ return undefined;
17
+ }
18
+ const server = jid.slice(sepIdx + 1);
19
+ const userCombined = jid.slice(0, sepIdx);
20
+ const [userAgent, device] = userCombined.split(':');
21
+ const user = userAgent.split('_')[0];
22
+ return {
23
+ server,
24
+ user,
25
+ domainType: server === 'lid' ? 1 : 0,
26
+ device: device ? +device : undefined
27
+ };
28
+ };
29
+ exports.jidDecode = jidDecode;
30
+ /** is the jid a user */
31
+ const areJidsSameUser = (jid1, jid2) => {
32
+ var _a, _b;
33
+ return (((_a = (0, exports.jidDecode)(jid1)) === null || _a === void 0 ? void 0 : _a.user) === ((_b = (0, exports.jidDecode)(jid2)) === null || _b === void 0 ? void 0 : _b.user));
34
+ };
35
+ exports.areJidsSameUser = areJidsSameUser;
36
+ /** is the jid a user */
37
+ const isJidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@s.whatsapp.net'));
38
+ exports.isJidUser = isJidUser;
39
+ /** is the jid a group */
40
+ const isLidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@lid'));
41
+ exports.isLidUser = isLidUser;
42
+ /** is the jid a broadcast */
43
+ const isJidBroadcast = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@broadcast'));
44
+ exports.isJidBroadcast = isJidBroadcast;
45
+ /** is the jid a group */
46
+ const isJidGroup = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@g.us'));
47
+ exports.isJidGroup = isJidGroup;
48
+ /** is the jid the status broadcast */
49
+ const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
50
+ exports.isJidStatusBroadcast = isJidStatusBroadcast;
51
+ /** is the jid the newsletter */
52
+ const isJidNewsLetter = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('newsletter'));
53
+ exports.isJidNewsLetter = isJidNewsLetter;
54
+ const jidNormalizedUser = (jid) => {
55
+ const result = (0, exports.jidDecode)(jid);
56
+ if (!result) {
57
+ return '';
58
+ }
59
+ const { user, server } = result;
60
+ return (0, exports.jidEncode)(user, server === 'c.us' ? 's.whatsapp.net' : server);
61
+ };
62
+ exports.jidNormalizedUser = jidNormalizedUser;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ellxz24/baileys",
3
- "version": "2.0.29",
3
+ "version": "2.0.31",
4
4
  "description": "WhatsApp API Modification By L",
5
5
  "publishConfig": {
6
6
  "access": "public"