@hbmodsofc/baileys 1.7.8 → 2.0.0

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.
Files changed (155) hide show
  1. package/LICENSE +1 -1
  2. package/WAProto/index.js +157084 -24729
  3. package/lib/Defaults/baileys-version.json +3 -0
  4. package/lib/Defaults/index.d.ts +8 -12
  5. package/lib/Defaults/index.js +124 -90
  6. package/lib/Defaults/phonenumber-mcc.json +223 -0
  7. package/lib/Signal/Group/group_cipher.d.ts +1 -0
  8. package/lib/Signal/Group/group_cipher.js +39 -28
  9. package/lib/Signal/Group/queue-job.d.ts +1 -0
  10. package/lib/Signal/Group/queue-job.js +57 -0
  11. package/lib/Signal/Group/sender-chain-key.d.ts +1 -1
  12. package/lib/Signal/Group/sender-chain-key.js +2 -9
  13. package/lib/Signal/Group/sender-key-distribution-message.js +3 -3
  14. package/lib/Signal/Group/sender-key-message.js +3 -3
  15. package/lib/Signal/Group/sender-key-state.d.ts +4 -4
  16. package/lib/Signal/Group/sender-key-state.js +16 -47
  17. package/lib/Signal/libsignal.d.ts +3 -7
  18. package/lib/Signal/libsignal.js +39 -224
  19. package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +3 -1
  20. package/lib/Socket/Client/index.d.ts +3 -2
  21. package/lib/Socket/Client/index.js +3 -2
  22. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  23. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  24. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
  25. package/lib/Socket/Client/{websocket.js → web-socket-client.js} +16 -10
  26. package/lib/Socket/business.d.ts +78 -94
  27. package/lib/Socket/business.js +11 -130
  28. package/lib/Socket/chats.d.ts +233 -63
  29. package/lib/Socket/chats.js +184 -234
  30. package/lib/Socket/groups.d.ts +41 -62
  31. package/lib/Socket/groups.js +64 -76
  32. package/lib/Socket/hbmods.d.ts +253 -0
  33. package/lib/Socket/hbmods.js +1 -0
  34. package/lib/Socket/index.d.ts +83 -129
  35. package/lib/Socket/index.js +6 -13
  36. package/lib/Socket/messages-recv.d.ts +48 -59
  37. package/lib/Socket/messages-recv.js +371 -516
  38. package/lib/Socket/messages-send.d.ts +67 -86
  39. package/lib/Socket/messages-send.js +1 -1091
  40. package/lib/Socket/newsletter.d.ts +64 -76
  41. package/lib/Socket/newsletter.js +1 -184
  42. package/lib/Socket/registration.d.ts +267 -0
  43. package/lib/Socket/registration.js +166 -0
  44. package/lib/Socket/socket.d.ts +13 -19
  45. package/lib/Socket/socket.js +1 -805
  46. package/lib/Socket/usync.d.ts +36 -0
  47. package/lib/Socket/usync.js +70 -0
  48. package/lib/Types/Auth.d.ts +10 -4
  49. package/lib/Types/Call.d.ts +1 -1
  50. package/lib/Types/Chat.d.ts +9 -29
  51. package/lib/Types/Chat.js +1 -7
  52. package/lib/Types/Contact.d.ts +1 -5
  53. package/lib/Types/Events.d.ts +14 -55
  54. package/lib/Types/GroupMetadata.d.ts +5 -15
  55. package/lib/Types/Label.d.ts +0 -11
  56. package/lib/Types/Label.js +1 -1
  57. package/lib/Types/LabelAssociation.js +1 -1
  58. package/lib/Types/Message.d.ts +49 -75
  59. package/lib/Types/Message.js +7 -10
  60. package/lib/Types/Newsletter.d.ts +98 -129
  61. package/lib/Types/Newsletter.js +38 -33
  62. package/lib/Types/Product.d.ts +1 -1
  63. package/lib/Types/Signal.d.ts +1 -29
  64. package/lib/Types/Socket.d.ts +22 -48
  65. package/lib/Types/State.d.ts +2 -13
  66. package/lib/Types/State.js +0 -12
  67. package/lib/Types/USync.d.ts +1 -1
  68. package/lib/Types/index.d.ts +3 -10
  69. package/lib/Types/index.js +2 -2
  70. package/lib/Utils/auth-utils.d.ts +3 -3
  71. package/lib/Utils/auth-utils.js +102 -378
  72. package/lib/Utils/baileys-event-stream.js +1 -1
  73. package/lib/Utils/business.d.ts +2 -2
  74. package/lib/Utils/business.js +13 -19
  75. package/lib/Utils/chat-utils.d.ts +22 -21
  76. package/lib/Utils/chat-utils.js +154 -201
  77. package/lib/Utils/crypto.d.ts +19 -18
  78. package/lib/Utils/crypto.js +37 -78
  79. package/lib/Utils/decode-wa-message.d.ts +7 -34
  80. package/lib/Utils/decode-wa-message.js +66 -138
  81. package/lib/Utils/event-buffer.d.ts +8 -6
  82. package/lib/Utils/event-buffer.js +43 -81
  83. package/lib/Utils/generics.d.ts +27 -27
  84. package/lib/Utils/generics.js +133 -128
  85. package/lib/Utils/history.d.ts +5 -9
  86. package/lib/Utils/history.js +23 -17
  87. package/lib/Utils/index.d.ts +0 -2
  88. package/lib/Utils/index.js +0 -2
  89. package/lib/Utils/link-preview.d.ts +4 -4
  90. package/lib/Utils/link-preview.js +12 -40
  91. package/lib/Utils/logger.d.ts +3 -11
  92. package/lib/Utils/lt-hash.d.ts +8 -8
  93. package/lib/Utils/lt-hash.js +24 -23
  94. package/lib/Utils/make-mutex.d.ts +2 -2
  95. package/lib/Utils/make-mutex.js +2 -3
  96. package/lib/Utils/messages-media.d.ts +41 -37
  97. package/lib/Utils/messages-media.js +368 -252
  98. package/lib/Utils/messages.d.ts +15 -13
  99. package/lib/Utils/messages.js +261 -274
  100. package/lib/Utils/noise-handler.d.ts +15 -13
  101. package/lib/Utils/noise-handler.js +26 -20
  102. package/lib/Utils/process-message.d.ts +8 -9
  103. package/lib/Utils/process-message.js +93 -157
  104. package/lib/Utils/signal.d.ts +5 -6
  105. package/lib/Utils/signal.js +29 -37
  106. package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
  107. package/lib/Utils/use-multi-file-auth-state.js +7 -12
  108. package/lib/Utils/validate-connection.d.ts +6 -5
  109. package/lib/Utils/validate-connection.js +97 -39
  110. package/lib/WABinary/constants.d.ts +27 -24
  111. package/lib/WABinary/constants.js +13 -1276
  112. package/lib/WABinary/decode.d.ts +4 -3
  113. package/lib/WABinary/decode.js +14 -28
  114. package/lib/WABinary/encode.d.ts +2 -1
  115. package/lib/WABinary/encode.js +147 -134
  116. package/lib/WABinary/generic-utils.d.ts +7 -4
  117. package/lib/WABinary/generic-utils.js +125 -40
  118. package/lib/WABinary/jid-utils.d.ts +8 -13
  119. package/lib/WABinary/jid-utils.js +16 -27
  120. package/lib/WAM/BinaryInfo.d.ts +11 -2
  121. package/lib/WAM/constants.d.ts +2 -3
  122. package/lib/WAM/constants.js +2359 -2252
  123. package/lib/WAM/encode.d.ts +2 -1
  124. package/lib/WAM/encode.js +11 -8
  125. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +2 -2
  126. package/lib/WAUSync/Protocols/USyncContactProtocol.js +4 -3
  127. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -2
  128. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +5 -5
  129. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -2
  130. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +5 -5
  131. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -2
  132. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +6 -5
  133. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +2 -2
  134. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
  135. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -4
  136. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +3 -11
  137. package/lib/WAUSync/USyncQuery.d.ts +2 -2
  138. package/lib/WAUSync/USyncQuery.js +15 -19
  139. package/lib/WAUSync/USyncUser.d.ts +5 -5
  140. package/lib/WAUSync/index.d.ts +1 -1
  141. package/lib/WAUSync/index.js +1 -1
  142. package/package.json +102 -104
  143. package/lib/Signal/lid-mapping.d.ts +0 -26
  144. package/lib/Signal/lid-mapping.js +0 -146
  145. package/lib/Socket/communities.d.ts +0 -232
  146. package/lib/Socket/communities.js +0 -402
  147. package/lib/Socket/mex.d.ts +0 -2
  148. package/lib/Socket/mex.js +0 -45
  149. package/lib/Types/Bussines.d.ts +0 -24
  150. package/lib/Types/Bussines.js +0 -2
  151. package/lib/Utils/lidToJid-test.d.ts +0 -11
  152. package/lib/Utils/lidToJid-test.js +0 -27
  153. package/lib/Utils/message-retry-manager.d.ts +0 -81
  154. package/lib/Utils/message-retry-manager.js +0 -152
  155. /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
@@ -1,152 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MessageRetryManager = void 0;
4
- const lru_cache_1 = require("lru-cache");
5
- /** Number of sent messages to cache in memory for handling retry receipts */
6
- const RECENT_MESSAGES_SIZE = 512;
7
- /** Timeout for session recreation - 1 hour */
8
- const RECREATE_SESSION_TIMEOUT = 60 * 60 * 1000; // 1 hour in milliseconds
9
- const PHONE_REQUEST_DELAY = 3000;
10
- class MessageRetryManager {
11
- constructor(logger, maxMsgRetryCount) {
12
- this.logger = logger;
13
- this.recentMessagesMap = new lru_cache_1.LRUCache({
14
- max: RECENT_MESSAGES_SIZE
15
- });
16
- this.sessionRecreateHistory = new lru_cache_1.LRUCache({
17
- ttl: RECREATE_SESSION_TIMEOUT * 2,
18
- ttlAutopurge: true
19
- });
20
- this.retryCounters = new lru_cache_1.LRUCache({
21
- ttl: 15 * 60 * 1000,
22
- ttlAutopurge: true,
23
- updateAgeOnGet: true
24
- }); // 15 minutes TTL
25
- this.pendingPhoneRequests = {};
26
- this.maxMsgRetryCount = 5;
27
- this.statistics = {
28
- totalRetries: 0,
29
- successfulRetries: 0,
30
- failedRetries: 0,
31
- mediaRetries: 0,
32
- sessionRecreations: 0,
33
- phoneRequests: 0
34
- };
35
- this.maxMsgRetryCount = maxMsgRetryCount;
36
- }
37
- /**
38
- * Add a recent message to the cache for retry handling
39
- */
40
- addRecentMessage(to, id, message) {
41
- const key = { to, id };
42
- const keyStr = this.keyToString(key);
43
- // Add new message
44
- this.recentMessagesMap.set(keyStr, {
45
- message,
46
- timestamp: Date.now()
47
- });
48
- this.logger.debug(`Added message to retry cache: ${to}/${id}`);
49
- }
50
- /**
51
- * Get a recent message from the cache
52
- */
53
- getRecentMessage(to, id) {
54
- const key = { to, id };
55
- const keyStr = this.keyToString(key);
56
- return this.recentMessagesMap.get(keyStr);
57
- }
58
- /**
59
- * Check if a session should be recreated based on retry count and history
60
- */
61
- shouldRecreateSession(jid, retryCount, hasSession) {
62
- // If we don't have a session, always recreate
63
- if (!hasSession) {
64
- this.sessionRecreateHistory.set(jid, Date.now());
65
- this.statistics.sessionRecreations++;
66
- return {
67
- reason: "we don't have a Signal session with them",
68
- recreate: true
69
- };
70
- }
71
- // Only consider recreation if retry count > 1
72
- if (retryCount < 2) {
73
- return { reason: '', recreate: false };
74
- }
75
- const now = Date.now();
76
- const prevTime = this.sessionRecreateHistory.get(jid);
77
- // If no previous recreation or it's been more than an hour
78
- if (!prevTime || now - prevTime > RECREATE_SESSION_TIMEOUT) {
79
- this.sessionRecreateHistory.set(jid, now);
80
- this.statistics.sessionRecreations++;
81
- return {
82
- reason: 'retry count > 1 and over an hour since last recreation',
83
- recreate: true
84
- };
85
- }
86
- return { reason: '', recreate: false };
87
- }
88
- /**
89
- * Increment retry counter for a message
90
- */
91
- incrementRetryCount(messageId) {
92
- this.retryCounters.set(messageId, (this.retryCounters.get(messageId) || 0) + 1);
93
- this.statistics.totalRetries++;
94
- return this.retryCounters.get(messageId);
95
- }
96
- /**
97
- * Get retry count for a message
98
- */
99
- getRetryCount(messageId) {
100
- return this.retryCounters.get(messageId) || 0;
101
- }
102
- /**
103
- * Check if message has exceeded maximum retry attempts
104
- */
105
- hasExceededMaxRetries(messageId) {
106
- return this.getRetryCount(messageId) >= this.maxMsgRetryCount;
107
- }
108
- /**
109
- * Mark retry as successful
110
- */
111
- markRetrySuccess(messageId) {
112
- this.statistics.successfulRetries++;
113
- // Clean up retry counter for successful message
114
- this.retryCounters.delete(messageId);
115
- this.cancelPendingPhoneRequest(messageId);
116
- }
117
- /**
118
- * Mark retry as failed
119
- */
120
- markRetryFailed(messageId) {
121
- this.statistics.failedRetries++;
122
- this.retryCounters.delete(messageId);
123
- }
124
- /**
125
- * Schedule a phone request with delay
126
- */
127
- schedulePhoneRequest(messageId, callback, delay = PHONE_REQUEST_DELAY) {
128
- // Cancel any existing request for this message
129
- this.cancelPendingPhoneRequest(messageId);
130
- this.pendingPhoneRequests[messageId] = setTimeout(() => {
131
- delete this.pendingPhoneRequests[messageId];
132
- this.statistics.phoneRequests++;
133
- callback();
134
- }, delay);
135
- this.logger.debug(`Scheduled phone request for message ${messageId} with ${delay}ms delay`);
136
- }
137
- /**
138
- * Cancel pending phone request
139
- */
140
- cancelPendingPhoneRequest(messageId) {
141
- const timeout = this.pendingPhoneRequests[messageId];
142
- if (timeout) {
143
- clearTimeout(timeout);
144
- delete this.pendingPhoneRequests[messageId];
145
- this.logger.debug(`Cancelled pending phone request for message ${messageId}`);
146
- }
147
- }
148
- keyToString(key) {
149
- return `${key.to}:${key.id}`;
150
- }
151
- }
152
- exports.MessageRetryManager = MessageRetryManager;