@queenanya/baileys 7.4.14 → 7.5.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.
Files changed (110) hide show
  1. package/README.md +26 -26
  2. package/lib/Defaults/baileys-version.json +1 -1
  3. package/lib/Defaults/index.d.ts +1 -231
  4. package/lib/Defaults/index.js +11 -23
  5. package/lib/Socket/Client/index.d.ts +2 -3
  6. package/lib/Socket/Client/index.js +2 -3
  7. package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +1 -1
  8. package/lib/Socket/Client/{web-socket-client.js → websocket.js} +2 -2
  9. package/lib/Socket/business.d.ts +31 -28
  10. package/lib/Socket/chats.d.ts +17 -9
  11. package/lib/Socket/chats.js +115 -116
  12. package/lib/Socket/{registration.d.ts → communities.d.ts} +94 -145
  13. package/lib/Socket/communities.js +354 -0
  14. package/lib/Socket/groups.d.ts +23 -10
  15. package/lib/Socket/groups.js +12 -1
  16. package/lib/Socket/index.d.ts +69 -38
  17. package/lib/Socket/index.js +2 -2
  18. package/lib/Socket/messages-recv.d.ts +30 -28
  19. package/lib/Socket/messages-recv.js +291 -180
  20. package/lib/Socket/messages-send.d.ts +25 -19
  21. package/lib/Socket/messages-send.js +110 -76
  22. package/lib/Socket/newsletter.d.ts +19 -13
  23. package/lib/Socket/newsletter.js +67 -54
  24. package/lib/Socket/socket.d.ts +3 -1
  25. package/lib/Socket/socket.js +15 -17
  26. package/lib/Socket/usync.d.ts +38 -0
  27. package/lib/Socket/usync.js +70 -0
  28. package/lib/Store/make-cache-manager-store.d.ts +2 -1
  29. package/lib/Store/make-in-memory-store.js +13 -11
  30. package/lib/Store/make-ordered-dictionary.js +2 -2
  31. package/lib/Types/Auth.d.ts +1 -6
  32. package/lib/Types/Call.d.ts +1 -1
  33. package/lib/Types/Chat.d.ts +15 -7
  34. package/lib/Types/Contact.d.ts +6 -1
  35. package/lib/Types/Events.d.ts +44 -2
  36. package/lib/Types/GroupMetadata.d.ts +3 -1
  37. package/lib/Types/Label.d.ts +11 -0
  38. package/lib/Types/Message.d.ts +37 -30
  39. package/lib/Types/Newsletter.d.ts +0 -13
  40. package/lib/Types/Newsletter.js +1 -15
  41. package/lib/Types/Socket.d.ts +10 -3
  42. package/lib/Types/USync.d.ts +25 -0
  43. package/lib/Types/USync.js +2 -0
  44. package/lib/Types/index.d.ts +8 -0
  45. package/lib/Utils/auth-utils.js +1 -7
  46. package/lib/Utils/chat-utils.d.ts +5 -4
  47. package/lib/Utils/chat-utils.js +52 -20
  48. package/lib/Utils/crypto.d.ts +2 -1
  49. package/lib/Utils/crypto.js +4 -2
  50. package/lib/Utils/decode-wa-message.d.ts +1 -0
  51. package/lib/Utils/decode-wa-message.js +34 -14
  52. package/lib/Utils/event-buffer.js +14 -8
  53. package/lib/Utils/generics.d.ts +37 -13
  54. package/lib/Utils/generics.js +103 -18
  55. package/lib/Utils/history.d.ts +6 -2
  56. package/lib/Utils/history.js +3 -0
  57. package/lib/Utils/index.d.ts +1 -0
  58. package/lib/Utils/index.js +1 -0
  59. package/lib/Utils/link-preview.js +24 -1
  60. package/lib/Utils/logger.d.ts +1 -3
  61. package/lib/Utils/make-mutex.js +1 -0
  62. package/lib/Utils/messages-media.d.ts +3 -2
  63. package/lib/Utils/messages-media.js +17 -32
  64. package/lib/Utils/messages.d.ts +1 -0
  65. package/lib/Utils/messages.js +67 -72
  66. package/lib/Utils/noise-handler.d.ts +3 -3
  67. package/lib/Utils/noise-handler.js +7 -12
  68. package/lib/Utils/process-message.d.ts +3 -2
  69. package/lib/Utils/process-message.js +55 -21
  70. package/lib/Utils/signal.js +23 -16
  71. package/lib/Utils/use-multi-file-auth-state.js +17 -3
  72. package/lib/Utils/validate-connection.d.ts +0 -1
  73. package/lib/Utils/validate-connection.js +10 -44
  74. package/lib/WABinary/constants.js +5 -5
  75. package/lib/WABinary/decode.d.ts +3 -2
  76. package/lib/WABinary/decode.js +6 -4
  77. package/lib/WABinary/encode.d.ts +1 -2
  78. package/lib/WABinary/encode.js +8 -6
  79. package/lib/WABinary/generic-utils.d.ts +1 -0
  80. package/lib/WABinary/jid-utils.d.ts +3 -3
  81. package/lib/WABinary/jid-utils.js +5 -5
  82. package/lib/WAM/BinaryInfo.d.ts +3 -2
  83. package/lib/WAM/constants.d.ts +3 -2
  84. package/lib/WAM/encode.d.ts +1 -0
  85. package/lib/WAM/encode.js +2 -2
  86. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  87. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  88. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  89. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  90. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  91. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  92. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  93. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  94. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  95. package/lib/WAUSync/Protocols/index.js +20 -0
  96. package/lib/WAUSync/USyncQuery.d.ts +26 -0
  97. package/lib/WAUSync/USyncQuery.js +79 -0
  98. package/lib/WAUSync/USyncUser.d.ts +10 -0
  99. package/lib/WAUSync/USyncUser.js +22 -0
  100. package/lib/WAUSync/index.d.ts +3 -0
  101. package/lib/WAUSync/index.js +19 -0
  102. package/lib/index.d.ts +1 -0
  103. package/lib/index.js +1 -0
  104. package/package.json +36 -34
  105. package/lib/Defaults/phonenumber-mcc.json +0 -223
  106. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
  107. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  108. package/lib/Socket/registration.js +0 -166
  109. /package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +0 -0
  110. /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decryptMessageNode = exports.decodeMessageNode = void 0;
3
+ exports.decryptMessageNode = exports.decodeMessageNode = exports.NO_MESSAGE_FOUND_ERROR_TEXT = void 0;
4
4
  const boom_1 = require("@hapi/boom");
5
5
  const WAProto_1 = require("../../WAProto");
6
6
  const WABinary_1 = require("../WABinary");
7
7
  const generics_1 = require("./generics");
8
- const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
8
+ exports.NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
9
9
  /**
10
10
  * Decode the received node as a message.
11
11
  * @note this will only parse the message, not decrypt it
12
12
  */
13
13
  function decodeMessageNode(stanza, meId, meLid) {
14
- var _a, _b;
14
+ var _a, _b, _c, _d;
15
15
  let msgType;
16
16
  let chatId;
17
17
  let author;
@@ -55,6 +55,11 @@ function decodeMessageNode(stanza, meId, meLid) {
55
55
  author = participant;
56
56
  chatId = from;
57
57
  }
58
+ else if ((0, WABinary_1.isJidNewsletter)(from)) {
59
+ msgType = 'newsletter';
60
+ author = from;
61
+ chatId = from;
62
+ }
58
63
  else if ((0, WABinary_1.isJidBroadcast)(from)) {
59
64
  if (!participant) {
60
65
  throw new boom_1.Boom('No participant in group message');
@@ -69,7 +74,7 @@ function decodeMessageNode(stanza, meId, meLid) {
69
74
  chatId = from;
70
75
  author = participant;
71
76
  }
72
- else if ((0, WABinary_1.isJidNewsLetter)(from)) {
77
+ else if ((0, WABinary_1.isJidNewsletter)(from)) {
73
78
  msgType = 'newsletter';
74
79
  author = from;
75
80
  chatId = from;
@@ -77,13 +82,14 @@ function decodeMessageNode(stanza, meId, meLid) {
77
82
  else {
78
83
  throw new boom_1.Boom('Unknown message type', { data: stanza });
79
84
  }
80
- const fromMe = (0, WABinary_1.isJidNewsLetter)(from) ? !!((_a = stanza.attrs) === null || _a === void 0 ? void 0 : _a.is_sender) : ((0, WABinary_1.isLidUser)(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
81
- const pushname = stanza.attrs.notify;
85
+ const fromMe = (0, WABinary_1.isJidNewsletter)(from) ? !!((_a = stanza.attrs) === null || _a === void 0 ? void 0 : _a.is_sender) || false : ((0, WABinary_1.isLidUser)(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
86
+ const pushname = (_b = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _b === void 0 ? void 0 : _b.notify;
82
87
  const key = {
83
88
  remoteJid: chatId,
84
89
  fromMe,
85
90
  id: msgId,
86
- participant
91
+ participant,
92
+ server_id: (_c = stanza.attrs) === null || _c === void 0 ? void 0 : _c.server_id
87
93
  };
88
94
  const fullMessage = {
89
95
  key,
@@ -92,7 +98,7 @@ function decodeMessageNode(stanza, meId, meLid) {
92
98
  broadcast: (0, WABinary_1.isJidBroadcast)(from)
93
99
  };
94
100
  if (msgType === 'newsletter') {
95
- fullMessage.newsletterServerId = +((_b = stanza.attrs) === null || _b === void 0 ? void 0 : _b.server_id);
101
+ fullMessage.newsletterServerId = +((_d = stanza.attrs) === null || _d === void 0 ? void 0 : _d.server_id);
96
102
  }
97
103
  if (key.fromMe) {
98
104
  fullMessage.status = WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK;
@@ -126,7 +132,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
126
132
  }
127
133
  }
128
134
  }
129
- if ((0, WABinary_1.isJidNewsLetter)(fullMessage.key.remoteJid)) {
135
+ if ((0, WABinary_1.isJidNewsletter)(fullMessage.key.remoteJid)) {
130
136
  const node = (0, WABinary_1.getBinaryNodeChild)(stanza, 'plaintext');
131
137
  const msg = WAProto_1.proto.Message.decode(node === null || node === void 0 ? void 0 : node.content);
132
138
  await processSenderKeyDistribution(msg);
@@ -140,7 +146,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
140
146
  const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details);
141
147
  fullMessage.verifiedBizName = details.verifiedName;
142
148
  }
143
- if (tag !== 'enc') {
149
+ if (tag !== 'enc' && tag !== 'plaintext') {
144
150
  continue;
145
151
  }
146
152
  if (!(content instanceof Uint8Array)) {
@@ -149,7 +155,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
149
155
  decryptables += 1;
150
156
  let msgBuffer;
151
157
  try {
152
- const e2eType = attrs.type;
158
+ const e2eType = tag === 'plaintext' ? 'plaintext' : attrs.type;
153
159
  switch (e2eType) {
154
160
  case 'skmsg':
155
161
  msgBuffer = await repository.decryptGroupMessage({
@@ -167,12 +173,26 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
167
173
  ciphertext: content
168
174
  });
169
175
  break;
176
+ case 'plaintext':
177
+ msgBuffer = content;
178
+ break;
170
179
  default:
171
180
  throw new Error(`Unknown e2e type: ${e2eType}`);
172
181
  }
173
- let msg = WAProto_1.proto.Message.decode((0, generics_1.unpadRandomMax16)(msgBuffer));
182
+ let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' ? (0, generics_1.unpadRandomMax16)(msgBuffer) : msgBuffer);
174
183
  msg = ((_a = msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
175
- await processSenderKeyDistribution(msg);
184
+ if (msg.senderKeyDistributionMessage) {
185
+ //eslint-disable-next-line max-depth
186
+ try {
187
+ await repository.processSenderKeyDistributionMessage({
188
+ authorJid: author,
189
+ item: msg.senderKeyDistributionMessage
190
+ });
191
+ }
192
+ catch (err) {
193
+ logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
194
+ }
195
+ }
176
196
  if (fullMessage.message) {
177
197
  Object.assign(fullMessage.message, msg);
178
198
  }
@@ -190,7 +210,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
190
210
  // if nothing was found to decrypt
191
211
  if (!decryptables) {
192
212
  fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
193
- fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT, JSON.stringify(stanza, generics_1.BufferJSON.replacer)];
213
+ fullMessage.messageStubParameters = [exports.NO_MESSAGE_FOUND_ERROR_TEXT];
194
214
  }
195
215
  }
196
216
  };
@@ -138,7 +138,9 @@ const makeBufferData = () => {
138
138
  groupUpdates: {}
139
139
  };
140
140
  };
141
- function append(data, historyCache, event, eventData, logger) {
141
+ function append(data, historyCache, event,
142
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
143
+ eventData, logger) {
142
144
  var _a, _b, _c;
143
145
  switch (event) {
144
146
  case 'messaging-history.set':
@@ -176,6 +178,9 @@ function append(data, historyCache, event, eventData, logger) {
176
178
  }
177
179
  }
178
180
  data.historySets.empty = false;
181
+ data.historySets.syncType = eventData.syncType;
182
+ data.historySets.progress = eventData.progress;
183
+ data.historySets.peerDataRequestSessionId = eventData.peerDataRequestSessionId;
179
184
  data.historySets.isLatest = eventData.isLatest || data.historySets.isLatest;
180
185
  break;
181
186
  case 'chats.upsert':
@@ -442,7 +447,10 @@ function consolidateEvents(data) {
442
447
  chats: Object.values(data.historySets.chats),
443
448
  messages: Object.values(data.historySets.messages),
444
449
  contacts: Object.values(data.historySets.contacts),
445
- isLatest: data.historySets.isLatest
450
+ syncType: data.historySets.syncType,
451
+ progress: data.historySets.progress,
452
+ isLatest: data.historySets.isLatest,
453
+ peerDataRequestSessionId: data.historySets.peerDataRequestSessionId
446
454
  };
447
455
  }
448
456
  const chatUpsertList = Object.values(data.chatUpserts);
@@ -496,12 +504,10 @@ function consolidateEvents(data) {
496
504
  return map;
497
505
  }
498
506
  function concatChats(a, b) {
499
- if (b.unreadCount === null) {
500
- // neutralize unread counter
501
- if (a.unreadCount < 0) {
502
- a.unreadCount = undefined;
503
- b.unreadCount = undefined;
504
- }
507
+ if (b.unreadCount === null && // neutralize unread counter
508
+ a.unreadCount < 0) {
509
+ a.unreadCount = undefined;
510
+ b.unreadCount = undefined;
505
511
  }
506
512
  if (typeof a.unreadCount === 'number' && typeof b.unreadCount === 'number') {
507
513
  b = { ...b };
@@ -1,17 +1,22 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { AxiosRequestConfig } from 'axios';
3
4
  import { Logger } from 'pino';
4
5
  import { proto } from '../../WAProto';
5
- import { BaileysEventEmitter, BaileysEventMap, WACallUpdateType, WAVersion } from '../Types';
6
+ import { BaileysEventEmitter, BaileysEventMap, BrowsersMap, ConnectionState, WACallUpdateType, WAVersion } from '../Types';
6
7
  import { BinaryNode } from '../WABinary';
7
- export declare const Browsers: {
8
- ubuntu: (browser: any) => [string, string, string];
9
- macOS: (browser: any) => [string, string, string];
10
- baileys: (browser: any) => [string, string, string];
11
- windows: (browser: any) => [string, string, string];
12
- /** The appropriate browser based on your OS & release */
13
- appropriate: (browser: any) => [string, string, string];
14
- };
8
+ /**
9
+ const COMPANION_PLATFORM_MAP = {
10
+ 'Chrome': '49',
11
+ 'Edge': '50',
12
+ 'Firefox': '51',
13
+ 'Opera': '53',
14
+ 'Safari': '54'
15
+ }
16
+ */
17
+ export declare const Browsers: BrowsersMap;
18
+ /** Other Browser Support for Paircode */
19
+ export declare const getPlatformId: (browser: string) => any;
15
20
  export declare const BufferJSON: {
16
21
  replacer: (k: any, value: any) => any;
17
22
  reviver: (_: any, value: any) => any;
@@ -20,6 +25,7 @@ export declare const getKeyAuthor: (key: proto.IMessageKey | undefined | null, m
20
25
  export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer;
21
26
  export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array;
22
27
  export declare const encodeWAMessage: (message: proto.IMessage) => Buffer;
28
+ export declare const encodeNewsletterMessage: (message: proto.IMessage) => Uint8Array;
23
29
  export declare const generateRegistrationId: () => number;
24
30
  export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array;
25
31
  export declare const toNumber: (t: Long | number | null | undefined) => number;
@@ -39,15 +45,29 @@ export declare const delayCancellable: (ms: number) => {
39
45
  };
40
46
  export declare function promiseTimeout<T>(ms: number | undefined, promise: (resolve: (v: T) => void, reject: (error: any) => void) => void): Promise<T>;
41
47
  export declare const generateMessageIDV2: (userId?: string) => string;
48
+ export declare const generateMessageIDV3: (userId?: string) => string;
42
49
  export declare const generateMessageID: () => string;
43
50
  export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => boolean | undefined, timeoutMs?: number) => Promise<void>;
44
- export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
51
+ export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
45
52
  export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: Logger) => void;
46
53
  /**
47
- * utility that fetches latest baileys version from the master branch.
54
+ * utility that fetches latest baileys version from the main branch.
48
55
  * Use to ensure your WA connection is always on the latest version
49
56
  */
50
57
  export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<any>) => Promise<{
58
+ version: number[];
59
+ isLatest: boolean;
60
+ error?: undefined;
61
+ } | {
62
+ version: WAVersion;
63
+ isLatest: boolean;
64
+ error: any;
65
+ }>;
66
+ /**
67
+ * utility that fetches latest baileys version from the master branch.
68
+ * Use to ensure your WA connection is always on the latest version
69
+ */
70
+ export declare const fetchLatestBaileysVersion2: (options?: AxiosRequestConfig<any>) => Promise<{
51
71
  version: WAVersion;
52
72
  isLatest: boolean;
53
73
  error?: undefined;
@@ -60,7 +80,7 @@ export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<an
60
80
  * A utility that fetches the latest web version of whatsapp.
61
81
  * Use to ensure your WA connection is always on the latest version
62
82
  */
63
- export declare const fetchLatestWaWebVersion: (options: AxiosRequestConfig<any>) => Promise<{
83
+ export declare const fetchLatestWaWebVersion: (options: AxiosRequestConfig<{}>) => Promise<{
64
84
  version: WAVersion;
65
85
  isLatest: boolean;
66
86
  error?: undefined;
@@ -91,5 +111,9 @@ export declare const getCodeFromWSError: (error: Error) => number;
91
111
  * @param platform AuthenticationCreds.platform
92
112
  */
93
113
  export declare const isWABusinessPlatform: (platform: string) => boolean;
94
- export declare function trimUndefined(obj: any): any;
114
+ export declare function trimUndefined(obj: {
115
+ [_: string]: any;
116
+ }): {
117
+ [_: string]: any;
118
+ };
95
119
  export declare function bytesToCrockford(buffer: Buffer): string;
@@ -1,9 +1,32 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.bytesToCrockford = exports.trimUndefined = exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.bindWaitForEvent = exports.generateMessageID = exports.generateMessageIDV2 = exports.promiseTimeout = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.Browsers = void 0;
29
+ exports.bytesToCrockford = exports.trimUndefined = exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion2 = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.bindWaitForEvent = exports.generateMessageID = exports.generateMessageIDV3 = exports.generateMessageIDV2 = exports.promiseTimeout = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeNewsletterMessage = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
7
30
  const boom_1 = require("@hapi/boom");
8
31
  const axios_1 = __importDefault(require("axios"));
9
32
  const crypto_1 = require("crypto");
@@ -12,27 +35,49 @@ const WAProto_1 = require("../../WAProto");
12
35
  const baileys_version_json_1 = require("../Defaults/baileys-version.json");
13
36
  const Types_1 = require("../Types");
14
37
  const WABinary_1 = require("../WABinary");
38
+ /** Added Extra Browsers or Platforms*/
15
39
  const PLATFORM_MAP = {
16
40
  'aix': 'AIX',
17
41
  'darwin': 'Mac OS',
18
42
  'win32': 'Windows',
19
- 'android': 'Android'
43
+ 'android': 'Android',
44
+ 'freebsd': 'FreeBSD',
45
+ 'openbsd': 'OpenBSD',
46
+ 'sunos': 'Solaris'
20
47
  };
48
+ /**
49
+ const COMPANION_PLATFORM_MAP = {
50
+ 'Chrome': '49',
51
+ 'Edge': '50',
52
+ 'Firefox': '51',
53
+ 'Opera': '53',
54
+ 'Safari': '54'
55
+ }
56
+ */
21
57
  exports.Browsers = {
22
- ubuntu: browser => ['Ubuntu', browser, '20.0.04'],
23
- macOS: browser => ['Mac OS', browser, '10.15.7'],
24
- baileys: browser => ['Baileys', browser, '4.0.0'],
25
- windows: browser => ['Windows', browser, '10.0.22621'],
58
+ ubuntu: (browser) => ['Ubuntu', browser, '24.04.1'],
59
+ macOS: (browser) => ['Mac OS', browser, '14.4.1'],
60
+ baileys: (browser) => ['Baileys', browser, '6.7.9'],
61
+ windows: (browser) => ['Windows', browser, '10.0.22631'],
62
+ // iOS: (browser) => ['iOS', browser, '18.1'],
26
63
  /** The appropriate browser based on your OS & release */
27
- appropriate: browser => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
64
+ appropriate: (browser) => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
28
65
  };
66
+ /** Other Browser Support for Paircode */
67
+ const getPlatformId = (browser) => {
68
+ const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
69
+ return platformType ? platformType.toString().charCodeAt(0).toString() : '51'; // Firefox
70
+ };
71
+ exports.getPlatformId = getPlatformId;
29
72
  exports.BufferJSON = {
73
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
74
  replacer: (k, value) => {
31
75
  if (Buffer.isBuffer(value) || value instanceof Uint8Array || (value === null || value === void 0 ? void 0 : value.type) === 'Buffer') {
32
76
  return { type: 'Buffer', data: Buffer.from((value === null || value === void 0 ? void 0 : value.data) || value).toString('base64') };
33
77
  }
34
78
  return value;
35
79
  },
80
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
81
  reviver: (_, value) => {
37
82
  if (typeof value === 'object' && !!value && (value.buffer === true || value.type === 'Buffer')) {
38
83
  const val = value.data || value.value;
@@ -66,6 +111,8 @@ const unpadRandomMax16 = (e) => {
66
111
  exports.unpadRandomMax16 = unpadRandomMax16;
67
112
  const encodeWAMessage = (message) => ((0, exports.writeRandomPadMax16)(WAProto_1.proto.Message.encode(message).finish()));
68
113
  exports.encodeWAMessage = encodeWAMessage;
114
+ const encodeNewsletterMessage = (message) => (WAProto_1.proto.Message.encode(message).finish());
115
+ exports.encodeNewsletterMessage = encodeNewsletterMessage;
69
116
  const generateRegistrationId = () => {
70
117
  return Uint16Array.from((0, crypto_1.randomBytes)(2))[0] & 16383;
71
118
  };
@@ -80,7 +127,7 @@ const encodeBigEndian = (e, t = 4) => {
80
127
  return a;
81
128
  };
82
129
  exports.encodeBigEndian = encodeBigEndian;
83
- const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t);
130
+ const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t || 0);
84
131
  exports.toNumber = toNumber;
85
132
  /** unix timestamp of a date in seconds */
86
133
  const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
@@ -147,6 +194,7 @@ async function promiseTimeout(ms, promise) {
147
194
  return p;
148
195
  }
149
196
  exports.promiseTimeout = promiseTimeout;
197
+ //Useless but still keep this to avoid unexpected errors and bugs
150
198
  const generateMessageIDV2 = (userId) => {
151
199
  const data = Buffer.alloc(8 + 20 + 16);
152
200
  data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
@@ -160,11 +208,19 @@ const generateMessageIDV2 = (userId) => {
160
208
  const random = (0, crypto_1.randomBytes)(16);
161
209
  random.copy(data, 28);
162
210
  const hash = (0, crypto_1.createHash)('sha256').update(data).digest();
163
- return '_OLD_USER_' + hash.toString('hex').toUpperCase().substring(0, 18);
211
+ return 'ANYAWEB' + hash.toString('hex').toUpperCase().substring(0, 18);
164
212
  };
165
213
  exports.generateMessageIDV2 = generateMessageIDV2;
214
+ //Message ID function for Anya_Baileyz
215
+ //This V3 is RollBack Update Of Old Message ID
216
+ const generateMessageIDV3 = (userId) => {
217
+ let swebfix = 'ANYAWEB';
218
+ let swebRandom = (0, crypto_1.randomBytes)(5).toString('hex').toUpperCase().substring(0, 10);
219
+ return swebfix + swebRandom;
220
+ };
221
+ exports.generateMessageIDV3 = generateMessageIDV3;
166
222
  // generate a random ID to attach to a message
167
- const generateMessageID = () => 'FELZ' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
223
+ const generateMessageID = () => 'ANYAWEB' + (0, crypto_1.randomBytes)(10).toString('hex').toUpperCase();
168
224
  exports.generateMessageID = generateMessageID;
169
225
  function bindWaitForEvent(ev, event) {
170
226
  return async (check, timeoutMs) => {
@@ -197,8 +253,7 @@ exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
197
253
  const printQRIfNecessaryListener = (ev, logger) => {
198
254
  ev.on('connection.update', async ({ qr }) => {
199
255
  if (qr) {
200
- const QR = await import('qrcode-terminal')
201
- .then(m => m.default || m)
256
+ const QR = await Promise.resolve().then(() => __importStar(require('qrcode-terminal'))).then(m => m.default || m)
202
257
  .catch(() => {
203
258
  logger.error('QR code terminal not added as dependency');
204
259
  });
@@ -208,10 +263,36 @@ const printQRIfNecessaryListener = (ev, logger) => {
208
263
  };
209
264
  exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
210
265
  /**
211
- * utility that fetches latest baileys version from the master branch.
266
+ * utility that fetches latest baileys version from the main branch.
212
267
  * Use to ensure your WA connection is always on the latest version
213
268
  */
214
269
  const fetchLatestBaileysVersion = async (options = {}) => {
270
+ try {
271
+ const result = await axios_1.default.get('https://raw.githubusercontent.com/wppconnect-team/wa-version/main/versions.json', {
272
+ ...options,
273
+ responseType: 'json'
274
+ });
275
+ const version = result.data.versions[result.data.versions.length - 1].version.split('.');
276
+ const version2 = version[2].replace('-alpha', '');
277
+ return {
278
+ version: [+version[0], +version[1], +version2],
279
+ isLatest: true
280
+ };
281
+ }
282
+ catch (error) {
283
+ return {
284
+ version: baileys_version_json_1.version,
285
+ isLatest: false,
286
+ error
287
+ };
288
+ }
289
+ };
290
+ exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
291
+ /**
292
+ * utility that fetches latest baileys version from the master branch.
293
+ * Use to ensure your WA connection is always on the latest version
294
+ */
295
+ const fetchLatestBaileysVersion2 = async (options = {}) => {
215
296
  const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/baileys-version.json';
216
297
  try {
217
298
  const result = await axios_1.default.get(URL, {
@@ -231,7 +312,7 @@ const fetchLatestBaileysVersion = async (options = {}) => {
231
312
  };
232
313
  }
233
314
  };
234
- exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
315
+ exports.fetchLatestBaileysVersion2 = fetchLatestBaileysVersion2;
235
316
  /**
236
317
  * A utility that fetches the latest web version of whatsapp.
237
318
  * Use to ensure your WA connection is always on the latest version
@@ -312,7 +393,8 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
312
393
  status = 'timeout';
313
394
  }
314
395
  else {
315
- status = 'reject';
396
+ //fired when accepted/rejected/timeout/caller hangs up
397
+ status = 'terminate';
316
398
  }
317
399
  break;
318
400
  case 'reject':
@@ -338,7 +420,9 @@ const getCodeFromWSError = (error) => {
338
420
  statusCode = code;
339
421
  }
340
422
  }
341
- else if (((_b = error === null || error === void 0 ? void 0 : error.code) === null || _b === void 0 ? void 0 : _b.startsWith('E'))
423
+ else if (
424
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
425
+ ((_b = error === null || error === void 0 ? void 0 : error.code) === null || _b === void 0 ? void 0 : _b.startsWith('E'))
342
426
  || ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('timed out'))) { // handle ETIMEOUT, ENOTFOUND etc
343
427
  statusCode = 408;
344
428
  }
@@ -353,6 +437,7 @@ const isWABusinessPlatform = (platform) => {
353
437
  return platform === 'smbi' || platform === 'smba';
354
438
  };
355
439
  exports.isWABusinessPlatform = isWABusinessPlatform;
440
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
356
441
  function trimUndefined(obj) {
357
442
  for (const key in obj) {
358
443
  if (typeof obj[key] === 'undefined') {
@@ -367,8 +452,8 @@ function bytesToCrockford(buffer) {
367
452
  let value = 0;
368
453
  let bitCount = 0;
369
454
  const crockford = [];
370
- for (let i = 0; i < buffer.length; i++) {
371
- value = (value << 8) | (buffer[i] & 0xff);
455
+ for (const element of buffer) {
456
+ value = (value << 8) | (element & 0xff);
372
457
  bitCount += 8;
373
458
  while (bitCount >= 5) {
374
459
  crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
@@ -1,15 +1,19 @@
1
1
  import { AxiosRequestConfig } from 'axios';
2
2
  import { proto } from '../../WAProto';
3
3
  import { Chat, Contact } from '../Types';
4
- export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<proto.HistorySync>;
4
+ export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<proto.HistorySync>;
5
5
  export declare const processHistoryMessage: (item: proto.IHistorySync) => {
6
6
  chats: Chat[];
7
7
  contacts: Contact[];
8
8
  messages: proto.IWebMessageInfo[];
9
+ syncType: proto.HistorySync.HistorySyncType;
10
+ progress: number | null | undefined;
9
11
  };
10
- export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<{
12
+ export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<{
11
13
  chats: Chat[];
12
14
  contacts: Contact[];
13
15
  messages: proto.IWebMessageInfo[];
16
+ syncType: proto.HistorySync.HistorySyncType;
17
+ progress: number | null | undefined;
14
18
  }>;
15
19
  export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined;
@@ -32,6 +32,7 @@ const processHistoryMessage = (item) => {
32
32
  case WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
33
33
  case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:
34
34
  case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
35
+ case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
35
36
  for (const chat of item.conversations) {
36
37
  contacts.push({ id: chat.id, name: chat.name || undefined });
37
38
  const msgs = chat.messages || [];
@@ -74,6 +75,8 @@ const processHistoryMessage = (item) => {
74
75
  chats,
75
76
  contacts,
76
77
  messages,
78
+ syncType: item.syncType,
79
+ progress: item.progress
77
80
  };
78
81
  };
79
82
  exports.processHistoryMessage = processHistoryMessage;
@@ -11,6 +11,7 @@ export * from './chat-utils';
11
11
  export * from './lt-hash';
12
12
  export * from './auth-utils';
13
13
  export * from './baileys-event-stream';
14
+ export * from './use-single-file-auth-state';
14
15
  export * from './use-multi-file-auth-state';
15
16
  export * from './link-preview';
16
17
  export * from './event-buffer';
@@ -27,6 +27,7 @@ __exportStar(require("./chat-utils"), exports);
27
27
  __exportStar(require("./lt-hash"), exports);
28
28
  __exportStar(require("./auth-utils"), exports);
29
29
  __exportStar(require("./baileys-event-stream"), exports);
30
+ __exportStar(require("./use-single-file-auth-state"), exports);
30
31
  __exportStar(require("./use-multi-file-auth-state"), exports);
31
32
  __exportStar(require("./link-preview"), exports);
32
33
  __exportStar(require("./event-buffer"), exports);
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.getUrlInfo = void 0;
4
27
  const messages_1 = require("./messages");
@@ -25,7 +48,7 @@ const getUrlInfo = async (text, opts = {
25
48
  // retries
26
49
  const retries = 0;
27
50
  const maxRetry = 5;
28
- const { getLinkPreview } = await import('link-preview-js');
51
+ const { getLinkPreview } = await Promise.resolve().then(() => __importStar(require('link-preview-js')));
29
52
  let previewLink = text;
30
53
  if (!text.startsWith('https://') && !text.startsWith('http://')) {
31
54
  previewLink = 'https://' + previewLink;
@@ -1,4 +1,2 @@
1
- declare const _default: import("pino").Logger<{
2
- timestamp: () => string;
3
- }>;
1
+ declare const _default: import("pino").Logger<never, boolean>;
4
2
  export default _default;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeKeyedMutex = exports.makeMutex = void 0;
4
4
  const makeMutex = () => {
5
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
6
  let task = Promise.resolve();
6
7
  let taskTimeout;
7
8
  return {
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  /// <reference types="node" />
4
+ /// <reference types="node" />
4
5
  import { Boom } from '@hapi/boom';
5
6
  import { AxiosRequestConfig } from 'axios';
6
7
  import type { Logger } from 'pino';
@@ -99,7 +100,7 @@ export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaTyp
99
100
  export type MediaDownloadOptions = {
100
101
  startByte?: number;
101
102
  endByte?: number;
102
- options?: AxiosRequestConfig<any>;
103
+ options?: AxiosRequestConfig<{}>;
103
104
  };
104
105
  export declare const getUrlFromDirectPath: (directPath: string) => string;
105
106
  export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<Transform>;
@@ -115,7 +116,7 @@ export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logg
115
116
  */
116
117
  export declare const encryptMediaRetryRequest: (key: proto.IMessageKey, mediaKey: Buffer | Uint8Array, meId: string) => BinaryNode;
117
118
  export declare const decodeMediaRetryNode: (node: BinaryNode) => {
118
- key: proto.IMessageKey;
119
+ key: import("../Types").WAMessageKey;
119
120
  media?: {
120
121
  ciphertext: Uint8Array;
121
122
  iv: Uint8Array;