supunmd-bail 2.1.1 → 2.1.4

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 (216) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +428 -0
  3. package/WAProto/index.js +130529 -45236
  4. package/engine-requirements.js +1 -1
  5. package/lib/Defaults/baileys-version.json +1 -1
  6. package/lib/Defaults/index.d.ts +9 -18
  7. package/lib/Defaults/index.js +136 -104
  8. package/lib/Defaults/phonenumber-mcc.json +223 -0
  9. package/lib/Signal/Group/ciphertext-message.d.ts +0 -1
  10. package/lib/Signal/Group/ciphertext-message.js +5 -2
  11. package/lib/Signal/Group/group-session-builder.d.ts +3 -4
  12. package/lib/Signal/Group/group-session-builder.js +41 -7
  13. package/lib/Signal/Group/group_cipher.d.ts +4 -4
  14. package/lib/Signal/Group/group_cipher.js +51 -37
  15. package/lib/Signal/Group/index.d.ts +11 -12
  16. package/lib/Signal/Group/index.js +57 -12
  17. package/lib/Signal/Group/keyhelper.d.ts +1 -2
  18. package/lib/Signal/Group/keyhelper.js +44 -7
  19. package/lib/Signal/Group/queue-job.d.ts +0 -1
  20. package/lib/Signal/Group/queue-job.js +5 -2
  21. package/lib/Signal/Group/sender-chain-key.d.ts +2 -3
  22. package/lib/Signal/Group/sender-chain-key.js +15 -7
  23. package/lib/Signal/Group/sender-key-distribution-message.d.ts +1 -2
  24. package/lib/Signal/Group/sender-key-distribution-message.js +11 -8
  25. package/lib/Signal/Group/sender-key-message.d.ts +1 -2
  26. package/lib/Signal/Group/sender-key-message.js +12 -9
  27. package/lib/Signal/Group/sender-key-name.d.ts +0 -1
  28. package/lib/Signal/Group/sender-key-name.js +5 -2
  29. package/lib/Signal/Group/sender-key-record.d.ts +2 -3
  30. package/lib/Signal/Group/sender-key-record.js +21 -9
  31. package/lib/Signal/Group/sender-key-state.d.ts +6 -7
  32. package/lib/Signal/Group/sender-key-state.js +42 -27
  33. package/lib/Signal/Group/sender-message-key.d.ts +0 -1
  34. package/lib/Signal/Group/sender-message-key.js +7 -4
  35. package/lib/Signal/libsignal.d.ts +3 -5
  36. package/lib/Signal/libsignal.js +90 -258
  37. package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +3 -2
  38. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  39. package/lib/Socket/Client/index.d.ts +3 -3
  40. package/lib/Socket/Client/index.js +19 -3
  41. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  42. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  43. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -2
  44. package/lib/Socket/Client/web-socket-client.js +62 -0
  45. package/lib/Socket/business.d.ts +108 -125
  46. package/lib/Socket/business.js +43 -159
  47. package/lib/Socket/chats.d.ts +239 -70
  48. package/lib/Socket/chats.js +384 -363
  49. package/lib/Socket/dugong.d.ts +254 -0
  50. package/lib/Socket/dugong.js +484 -0
  51. package/lib/Socket/groups.d.ts +56 -78
  52. package/lib/Socket/groups.js +96 -106
  53. package/lib/Socket/index.d.ts +115 -173
  54. package/lib/Socket/index.js +10 -17
  55. package/lib/Socket/messages-recv.d.ts +79 -91
  56. package/lib/Socket/messages-recv.js +521 -639
  57. package/lib/Socket/messages-send.d.ts +91 -111
  58. package/lib/Socket/messages-send.js +438 -599
  59. package/lib/Socket/newsletter.d.ts +84 -97
  60. package/lib/Socket/newsletter.js +239 -145
  61. package/lib/Socket/registration.d.ts +267 -0
  62. package/lib/Socket/registration.js +166 -0
  63. package/lib/Socket/socket.d.ts +18 -26
  64. package/lib/Socket/socket.js +230 -448
  65. package/lib/Socket/usync.d.ts +16 -17
  66. package/lib/Socket/usync.js +26 -19
  67. package/lib/Store/index.d.ts +3 -0
  68. package/lib/Store/index.js +10 -0
  69. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  70. package/lib/Store/make-cache-manager-store.js +83 -0
  71. package/lib/Store/make-in-memory-store.d.ts +118 -0
  72. package/lib/Store/make-in-memory-store.js +427 -0
  73. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  74. package/lib/Store/make-ordered-dictionary.js +81 -0
  75. package/lib/Store/object-repository.d.ts +10 -0
  76. package/lib/Store/object-repository.js +27 -0
  77. package/lib/Types/Auth.d.ts +12 -13
  78. package/lib/Types/Auth.js +2 -2
  79. package/lib/Types/Call.d.ts +1 -2
  80. package/lib/Types/Call.js +2 -2
  81. package/lib/Types/Chat.d.ts +13 -34
  82. package/lib/Types/Chat.js +4 -8
  83. package/lib/Types/Contact.d.ts +1 -6
  84. package/lib/Types/Contact.js +2 -2
  85. package/lib/Types/Events.d.ts +15 -60
  86. package/lib/Types/Events.js +2 -2
  87. package/lib/Types/GroupMetadata.d.ts +5 -17
  88. package/lib/Types/GroupMetadata.js +2 -2
  89. package/lib/Types/Label.d.ts +0 -12
  90. package/lib/Types/Label.js +5 -3
  91. package/lib/Types/LabelAssociation.d.ts +0 -1
  92. package/lib/Types/LabelAssociation.js +5 -3
  93. package/lib/Types/Message.d.ts +54 -84
  94. package/lib/Types/Message.js +9 -11
  95. package/lib/Types/Newsletter.d.ts +98 -130
  96. package/lib/Types/Newsletter.js +38 -31
  97. package/lib/Types/Product.d.ts +1 -2
  98. package/lib/Types/Product.js +2 -2
  99. package/lib/Types/Signal.d.ts +1 -20
  100. package/lib/Types/Signal.js +2 -2
  101. package/lib/Types/Socket.d.ts +25 -47
  102. package/lib/Types/Socket.js +2 -3
  103. package/lib/Types/State.d.ts +2 -14
  104. package/lib/Types/State.js +2 -13
  105. package/lib/Types/USync.d.ts +2 -3
  106. package/lib/Types/USync.js +2 -2
  107. package/lib/Types/index.d.ts +14 -22
  108. package/lib/Types/index.js +31 -15
  109. package/lib/Utils/auth-utils.d.ts +6 -7
  110. package/lib/Utils/auth-utils.js +148 -199
  111. package/lib/Utils/baileys-event-stream.d.ts +1 -2
  112. package/lib/Utils/baileys-event-stream.js +22 -15
  113. package/lib/Utils/business.d.ts +2 -3
  114. package/lib/Utils/business.js +69 -66
  115. package/lib/Utils/chat-utils.d.ts +22 -21
  116. package/lib/Utils/chat-utils.js +226 -260
  117. package/lib/Utils/crypto.d.ts +19 -19
  118. package/lib/Utils/crypto.js +86 -77
  119. package/lib/Utils/decode-wa-message.d.ts +8 -37
  120. package/lib/Utils/decode-wa-message.js +83 -164
  121. package/lib/Utils/event-buffer.d.ts +8 -7
  122. package/lib/Utils/event-buffer.js +76 -110
  123. package/lib/Utils/generics.d.ts +29 -27
  124. package/lib/Utils/generics.js +210 -168
  125. package/lib/Utils/history.d.ts +8 -12
  126. package/lib/Utils/history.js +46 -34
  127. package/lib/Utils/index.d.ts +17 -20
  128. package/lib/Utils/index.js +33 -20
  129. package/lib/Utils/link-preview.d.ts +5 -5
  130. package/lib/Utils/link-preview.js +22 -14
  131. package/lib/Utils/logger.d.ts +3 -11
  132. package/lib/Utils/logger.js +7 -3
  133. package/lib/Utils/lt-hash.d.ts +8 -9
  134. package/lib/Utils/lt-hash.js +28 -25
  135. package/lib/Utils/make-mutex.d.ts +2 -3
  136. package/lib/Utils/make-mutex.js +10 -7
  137. package/lib/Utils/messages-media.d.ts +44 -42
  138. package/lib/Utils/messages-media.js +475 -319
  139. package/lib/Utils/messages.d.ts +18 -17
  140. package/lib/Utils/messages.js +259 -383
  141. package/lib/Utils/noise-handler.d.ts +15 -14
  142. package/lib/Utils/noise-handler.js +38 -30
  143. package/lib/Utils/process-message.d.ts +13 -14
  144. package/lib/Utils/process-message.js +147 -239
  145. package/lib/Utils/signal.d.ts +5 -7
  146. package/lib/Utils/signal.js +72 -78
  147. package/lib/Utils/use-multi-file-auth-state.d.ts +2 -2
  148. package/lib/Utils/use-multi-file-auth-state.js +27 -29
  149. package/lib/Utils/validate-connection.d.ts +7 -7
  150. package/lib/Utils/validate-connection.js +106 -72
  151. package/lib/WABinary/constants.d.ts +27 -25
  152. package/lib/WABinary/constants.js +20 -1281
  153. package/lib/WABinary/decode.d.ts +5 -5
  154. package/lib/WABinary/decode.js +42 -28
  155. package/lib/WABinary/encode.d.ts +3 -3
  156. package/lib/WABinary/encode.js +154 -105
  157. package/lib/WABinary/generic-utils.d.ts +7 -5
  158. package/lib/WABinary/generic-utils.js +63 -56
  159. package/lib/WABinary/index.d.ts +5 -6
  160. package/lib/WABinary/index.js +21 -6
  161. package/lib/WABinary/jid-utils.d.ts +8 -25
  162. package/lib/WABinary/jid-utils.js +40 -74
  163. package/lib/WABinary/types.d.ts +1 -2
  164. package/lib/WABinary/types.js +2 -2
  165. package/lib/WAM/BinaryInfo.d.ts +11 -3
  166. package/lib/WAM/BinaryInfo.js +5 -2
  167. package/lib/WAM/constants.d.ts +3 -5
  168. package/lib/WAM/constants.js +11958 -19461
  169. package/lib/WAM/encode.d.ts +3 -3
  170. package/lib/WAM/encode.js +22 -17
  171. package/lib/WAM/index.d.ts +3 -4
  172. package/lib/WAM/index.js +19 -4
  173. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -4
  174. package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -8
  175. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -3
  176. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
  177. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -3
  178. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -9
  179. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -3
  180. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
  181. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -4
  182. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
  183. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -5
  184. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +8 -13
  185. package/lib/WAUSync/Protocols/index.d.ts +4 -5
  186. package/lib/WAUSync/Protocols/index.js +20 -5
  187. package/lib/WAUSync/USyncQuery.d.ts +4 -5
  188. package/lib/WAUSync/USyncQuery.js +35 -40
  189. package/lib/WAUSync/USyncUser.d.ts +5 -6
  190. package/lib/WAUSync/USyncUser.js +5 -2
  191. package/lib/WAUSync/index.d.ts +3 -4
  192. package/lib/WAUSync/index.js +19 -4
  193. package/lib/index.d.ts +9 -19
  194. package/lib/index.js +47 -24
  195. package/package.json +109 -99
  196. package/WAProto/GenerateStatics.sh +0 -3
  197. package/WAProto/WAProto.proto +0 -5519
  198. package/WAProto/fix-imports.js +0 -29
  199. package/WAProto/index.d.ts +0 -11969
  200. package/lib/Signal/lid-mapping.d.ts +0 -23
  201. package/lib/Signal/lid-mapping.js +0 -171
  202. package/lib/Socket/Client/types.js +0 -11
  203. package/lib/Socket/Client/websocket.js +0 -50
  204. package/lib/Socket/communities.d.ts +0 -244
  205. package/lib/Socket/communities.js +0 -431
  206. package/lib/Socket/mex.d.ts +0 -3
  207. package/lib/Socket/mex.js +0 -42
  208. package/lib/Types/Bussines.d.ts +0 -25
  209. package/lib/Types/Bussines.js +0 -2
  210. package/lib/Utils/browser-utils.d.ts +0 -4
  211. package/lib/Utils/browser-utils.js +0 -28
  212. package/lib/Utils/message-retry-manager.d.ts +0 -82
  213. package/lib/Utils/message-retry-manager.js +0 -149
  214. package/lib/Utils/pre-key-manager.d.ts +0 -28
  215. package/lib/Utils/pre-key-manager.js +0 -106
  216. /package/lib/{supun → supunmd} +0 -0
@@ -1,42 +1,70 @@
1
- import { Boom } from '@hapi/boom';
2
- import { createHash, randomBytes } from 'crypto';
3
- import { proto } from '../../WAProto/index.js';
4
- const baileysVersion = [2, 3000, 1027934701];
5
- import { DisconnectReason } from '../Types/index.js';
6
- import { getAllBinaryNodeChildren, jidDecode } from '../WABinary/index.js';
7
- import { sha256 } from './crypto.js';
8
- export const BufferJSON = {
9
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
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.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;
7
+ const boom_1 = require("@hapi/boom");
8
+ const axios_1 = __importDefault(require("axios"));
9
+ const crypto_1 = require("crypto");
10
+ const os_1 = require("os");
11
+ const fetch_1 = require("node-fetch")
12
+ const WAProto_1 = require("../../WAProto");
13
+ const baileys_version_json_1 = require("../Defaults/baileys-version.json");
14
+ const Types_1 = require("../Types");
15
+ const WABinary_1 = require("../WABinary");
16
+ const baileysVersion = [2, 3000, 1027934701]
17
+ const PLATFORM_MAP = {
18
+ 'aix': 'AIX',
19
+ 'darwin': 'Mac OS',
20
+ 'win32': 'Windows',
21
+ 'android': 'Android',
22
+ 'freebsd': 'FreeBSD',
23
+ 'openbsd': 'OpenBSD',
24
+ 'sunos': 'Solaris',
25
+ 'linux': undefined,
26
+ 'haiku': undefined,
27
+ 'cygwin': undefined,
28
+ 'netbsd': undefined
29
+ };
30
+ exports.Browsers = (browser) => {
31
+ const osName = PLATFORM_MAP[os_1.platform()] || 'Ubuntu';
32
+ const osRelease = os_1.release();
33
+ return [osName, browser, osRelease];
34
+ };
35
+
36
+ const getPlatformId = (browser) => {
37
+ const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
38
+ return platformType ? platformType.toString() : '1'; //chrome
39
+ };
40
+ exports.getPlatformId = getPlatformId;
41
+ exports.BufferJSON = {
10
42
  replacer: (k, value) => {
11
- if (Buffer.isBuffer(value) || value instanceof Uint8Array || value?.type === 'Buffer') {
12
- return { type: 'Buffer', data: Buffer.from(value?.data || value).toString('base64') };
43
+ if (Buffer.isBuffer(value) || value instanceof Uint8Array || (value === null || value === void 0 ? void 0 : value.type) === 'Buffer') {
44
+ return { type: 'Buffer', data: Buffer.from((value === null || value === void 0 ? void 0 : value.data) || value).toString('base64') };
13
45
  }
14
46
  return value;
15
47
  },
16
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
48
  reviver: (_, value) => {
18
- if (typeof value === 'object' && value !== null && value.type === 'Buffer' && typeof value.data === 'string') {
19
- return Buffer.from(value.data, 'base64');
20
- }
21
- if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
22
- const keys = Object.keys(value);
23
- if (keys.length > 0 && keys.every(k => !isNaN(parseInt(k, 10)))) {
24
- const values = Object.values(value);
25
- if (values.every(v => typeof v === 'number')) {
26
- return Buffer.from(values);
27
- }
28
- }
49
+ if (typeof value === 'object' && !!value && (value.buffer === true || value.type === 'Buffer')) {
50
+ const val = value.data || value.value;
51
+ return typeof val === 'string' ? Buffer.from(val, 'base64') : Buffer.from(val || []);
29
52
  }
30
53
  return value;
31
54
  }
32
55
  };
33
- export const getKeyAuthor = (key, meId = 'me') => (key?.fromMe ? meId : key?.participant || key?.remoteJid) || '';
34
- export const writeRandomPadMax16 = (msg) => {
35
- const pad = randomBytes(1);
36
- const padLength = (pad[0] & 0x0f) + 1;
37
- return Buffer.concat([msg, Buffer.alloc(padLength, padLength)]);
56
+ const getKeyAuthor = (key, meId = 'me') => (((key === null || key === void 0 ? void 0 : key.fromMe) ? meId : (key === null || key === void 0 ? void 0 : key.participant) || (key === null || key === void 0 ? void 0 : key.remoteJid)) || '');
57
+ exports.getKeyAuthor = getKeyAuthor;
58
+ const writeRandomPadMax16 = (msg) => {
59
+ const pad = (0, crypto_1.randomBytes)(1);
60
+ pad[0] &= 0xf;
61
+ if (!pad[0]) {
62
+ pad[0] = 0xf;
63
+ }
64
+ return Buffer.concat([msg, Buffer.alloc(pad[0], pad[0])]);
38
65
  };
39
- export const unpadRandomMax16 = (e) => {
66
+ exports.writeRandomPadMax16 = writeRandomPadMax16;
67
+ const unpadRandomMax16 = (e) => {
40
68
  const t = new Uint8Array(e);
41
69
  if (0 === t.length) {
42
70
  throw new Error('unpadPkcs7 given empty bytes');
@@ -47,17 +75,14 @@ export const unpadRandomMax16 = (e) => {
47
75
  }
48
76
  return new Uint8Array(t.buffer, t.byteOffset, t.length - r);
49
77
  };
50
- // code is inspired by whatsmeow
51
- export const generateParticipantHashV2 = (participants) => {
52
- participants.sort();
53
- const sha256Hash = sha256(Buffer.from(participants.join(''))).toString('base64');
54
- return '2:' + sha256Hash.slice(0, 6);
55
- };
56
- export const encodeWAMessage = (message) => writeRandomPadMax16(proto.Message.encode(message).finish());
57
- export const generateRegistrationId = () => {
58
- return Uint16Array.from(randomBytes(2))[0] & 16383;
78
+ exports.unpadRandomMax16 = unpadRandomMax16;
79
+ const encodeWAMessage = (message) => ((0, exports.writeRandomPadMax16)(WAProto_1.proto.Message.encode(message).finish()));
80
+ exports.encodeWAMessage = encodeWAMessage;
81
+ const generateRegistrationId = () => {
82
+ return Uint16Array.from((0, crypto_1.randomBytes)(2))[0] & 16383;
59
83
  };
60
- export const encodeBigEndian = (e, t = 4) => {
84
+ exports.generateRegistrationId = generateRegistrationId;
85
+ const encodeBigEndian = (e, t = 4) => {
61
86
  let r = e;
62
87
  const a = new Uint8Array(t);
63
88
  for (let i = t - 1; i >= 0; i--) {
@@ -66,28 +91,33 @@ export const encodeBigEndian = (e, t = 4) => {
66
91
  }
67
92
  return a;
68
93
  };
69
- export const toNumber = (t) => typeof t === 'object' && t ? ('toNumber' in t ? t.toNumber() : t.low) : t || 0;
94
+ exports.encodeBigEndian = encodeBigEndian;
95
+ const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t);
96
+ exports.toNumber = toNumber;
70
97
  /** unix timestamp of a date in seconds */
71
- export const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
72
- export const debouncedTimeout = (intervalMs = 1000, task) => {
98
+ const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
99
+ exports.unixTimestampSeconds = unixTimestampSeconds;
100
+ const debouncedTimeout = (intervalMs = 1000, task) => {
73
101
  let timeout;
74
102
  return {
75
103
  start: (newIntervalMs, newTask) => {
76
104
  task = newTask || task;
77
105
  intervalMs = newIntervalMs || intervalMs;
78
106
  timeout && clearTimeout(timeout);
79
- timeout = setTimeout(() => task?.(), intervalMs);
107
+ timeout = setTimeout(() => task === null || task === void 0 ? void 0 : task(), intervalMs);
80
108
  },
81
109
  cancel: () => {
82
110
  timeout && clearTimeout(timeout);
83
111
  timeout = undefined;
84
112
  },
85
- setTask: (newTask) => (task = newTask),
86
- setInterval: (newInterval) => (intervalMs = newInterval)
113
+ setTask: (newTask) => task = newTask,
114
+ setInterval: (newInterval) => intervalMs = newInterval
87
115
  };
88
116
  };
89
- export const delay = (ms) => delayCancellable(ms).delay;
90
- export const delayCancellable = (ms) => {
117
+ exports.debouncedTimeout = debouncedTimeout;
118
+ const delay = (ms) => (0, exports.delayCancellable)(ms).delay;
119
+ exports.delay = delay;
120
+ const delayCancellable = (ms) => {
91
121
  const stack = new Error().stack;
92
122
  let timeout;
93
123
  let reject;
@@ -97,7 +127,7 @@ export const delayCancellable = (ms) => {
97
127
  });
98
128
  const cancel = () => {
99
129
  clearTimeout(timeout);
100
- reject(new Boom('Cancelled', {
130
+ reject(new boom_1.Boom('Cancelled', {
101
131
  statusCode: 500,
102
132
  data: {
103
133
  stack
@@ -106,188 +136,198 @@ export const delayCancellable = (ms) => {
106
136
  };
107
137
  return { delay, cancel };
108
138
  };
109
- export async function promiseTimeout(ms, promise) {
139
+ exports.delayCancellable = delayCancellable;
140
+ async function promiseTimeout(ms, promise) {
110
141
  if (!ms) {
111
142
  return new Promise(promise);
112
143
  }
113
144
  const stack = new Error().stack;
114
145
  // Create a promise that rejects in <ms> milliseconds
115
- const { delay, cancel } = delayCancellable(ms);
146
+ const { delay, cancel } = (0, exports.delayCancellable)(ms);
116
147
  const p = new Promise((resolve, reject) => {
117
148
  delay
118
- .then(() => reject(new Boom('Timed Out', {
119
- statusCode: DisconnectReason.timedOut,
149
+ .then(() => reject(new boom_1.Boom('Timed Out', {
150
+ statusCode: Types_1.DisconnectReason.timedOut,
120
151
  data: {
121
152
  stack
122
153
  }
123
154
  })))
124
155
  .catch(err => reject(err));
125
156
  promise(resolve, reject);
126
- }).finally(cancel);
157
+ })
158
+ .finally(cancel);
127
159
  return p;
128
160
  }
129
- // inspired from whatsmeow code
130
- // https://github.com/tulir/whatsmeow/blob/64bc969fbe78d31ae0dd443b8d4c80a5d026d07a/send.go#L42
131
- export const generateMessageIDV2 = (userId) => {
161
+ exports.promiseTimeout = promiseTimeout;
162
+ const generateMessageIDV2 = (userId) => {
132
163
  const data = Buffer.alloc(8 + 20 + 16);
133
164
  data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
134
165
  if (userId) {
135
- const id = jidDecode(userId);
136
- if (id?.user) {
166
+ const id = (0, WABinary_1.jidDecode)(userId);
167
+ if (id === null || id === void 0 ? void 0 : id.user) {
137
168
  data.write(id.user, 8);
138
169
  data.write('@c.us', 8 + id.user.length);
139
170
  }
140
171
  }
141
- const random = randomBytes(16);
172
+ const random = (0, crypto_1.randomBytes)(16);
142
173
  random.copy(data, 28);
143
- const hash = createHash('sha256').update(data).digest();
144
- return 'KYUU-' + hash.toString('hex').toUpperCase().substring(0, 18);
174
+ const hash = (0, crypto_1.createHash)('sha256').update(data).digest();
175
+ return '3EB0' + hash.toString('hex').toUpperCase().substring(0, 18);
145
176
  };
177
+ exports.generateMessageIDV2 = generateMessageIDV2;
146
178
  // generate a random ID to attach to a message
147
- export const generateMessageID = () => 'KYUU-' + randomBytes(8).toString('hex').toUpperCase();
148
- export function bindWaitForEvent(ev, event) {
179
+ const generateMessageID = () => 'ILSYM-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
180
+ exports.generateMessageID = generateMessageID;
181
+ function bindWaitForEvent(ev, event) {
149
182
  return async (check, timeoutMs) => {
150
183
  let listener;
151
184
  let closeListener;
152
- await promiseTimeout(timeoutMs, (resolve, reject) => {
185
+ await (promiseTimeout(timeoutMs, (resolve, reject) => {
153
186
  closeListener = ({ connection, lastDisconnect }) => {
154
187
  if (connection === 'close') {
155
- reject(lastDisconnect?.error || new Boom('Connection Closed', { statusCode: DisconnectReason.connectionClosed }));
188
+ reject((lastDisconnect === null || lastDisconnect === void 0 ? void 0 : lastDisconnect.error)
189
+ || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
156
190
  }
157
191
  };
158
192
  ev.on('connection.update', closeListener);
159
- listener = async (update) => {
160
- if (await check(update)) {
193
+ listener = (update) => {
194
+ if (check(update)) {
161
195
  resolve();
162
196
  }
163
197
  };
164
198
  ev.on(event, listener);
165
- }).finally(() => {
199
+ })
200
+ .finally(() => {
166
201
  ev.off(event, listener);
167
202
  ev.off('connection.update', closeListener);
168
- });
203
+ }));
169
204
  };
170
205
  }
171
- export const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
206
+ exports.bindWaitForEvent = bindWaitForEvent;
207
+ const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
208
+ exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
209
+ const printQRIfNecessaryListener = (ev, logger) => {
210
+ ev.on('connection.update', async ({ qr }) => {
211
+ if (qr) {
212
+ const QR = await import('qrcode-terminal')
213
+ .then(m => m.default || m)
214
+ .catch(() => {
215
+ logger.error('QR code terminal not added as dependency');
216
+ });
217
+ QR === null || QR === void 0 ? void 0 : QR.generate(qr, { small: true });
218
+ }
219
+ });
220
+ };
221
+ exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
172
222
  /**
173
223
  * utility that fetches latest baileys version from the master branch.
174
224
  * Use to ensure your WA connection is always on the latest version
175
225
  */
176
- export const fetchLatestBaileysVersion = async (options = {}) => {
177
- const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/index.ts';
178
- try {
179
- const response = await fetch(URL, {
180
- dispatcher: options.dispatcher,
181
- method: 'GET',
182
- headers: options.headers
183
- });
184
- if (!response.ok) {
185
- throw new Boom(`Failed to fetch latest Baileys version: ${response.statusText}`, { statusCode: response.status });
186
- }
187
- const text = await response.text();
188
- // Extract version from line 7 (const version = [...])
189
- const lines = text.split('\n');
190
- const versionLine = lines[6]; // Line 7 (0-indexed)
191
- const versionMatch = versionLine.match(/const version = \[(\d+),\s*(\d+),\s*(\d+)\]/);
192
- if (versionMatch) {
193
- const version = [parseInt(versionMatch[1]), parseInt(versionMatch[2]), parseInt(versionMatch[3])];
194
- return {
195
- version,
196
- isLatest: true
197
- };
198
- }
199
- else {
200
- throw new Error('Could not parse version from Defaults/index.ts');
201
- }
202
- }
203
- catch (error) {
204
- return {
205
- version: baileysVersion,
206
- isLatest: false,
207
- error
208
- };
209
- }
210
- };
226
+ const fetchLatestWaWebVersion = async (options = {}) => {
227
+ try {
228
+ const defaultHeaders = {
229
+ 'User-Agent':
230
+ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
231
+ 'Accept': '*/*'
232
+ }
233
+
234
+ const headers = { ...defaultHeaders, ...options.headers }
235
+
236
+ const response = await fetch_1('https://web.whatsapp.com/sw.js', {
237
+ method: 'GET',
238
+ headers
239
+ })
240
+
241
+ if (!response.ok) {
242
+ throw new Error(`Failed to fetch sw.js: ${response.status} ${response.statusText}`)
243
+ }
244
+
245
+ const data = await response.text()
246
+ const regex = /"client_revision":\s*(\d+)/ // regex cukup begini untuk Node
247
+ const match = data.match(regex)
248
+
249
+ if (!match || !match[1]) {
250
+ return {
251
+ version: baileysVersion,
252
+ isLatest: false,
253
+ error: { message: 'Client revision not found' }
254
+ }
255
+ }
256
+
257
+ const clientRevision = match[1]
258
+ return {
259
+ version: [2, 3000, +clientRevision],
260
+ isLatest: true
261
+ }
262
+ } catch (error) {
263
+ return {
264
+ version: baileysVersion,
265
+ isLatest: false,
266
+ error
267
+ }
268
+ }
269
+ }
270
+ exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
211
271
  /**
212
- * A utility that fetches the latest web version of whatsapp.
272
+ * utility that fetches latest baileys version from the master branch.
213
273
  * Use to ensure your WA connection is always on the latest version
214
274
  */
215
- export const fetchLatestWaWebVersion = async (options = {}) => {
275
+ const fetchLatestBaileysVersion = async (options = {}) => {
276
+ const URL = 'https://raw.githubusercontent.com/kiuur/bails/master/src/Defaults/baileys-version.json';
216
277
  try {
217
- // Absolute minimal headers required to bypass anti-bot detection
218
- const defaultHeaders = {
219
- 'sec-fetch-site': 'none',
220
- 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
221
- };
222
- const headers = { ...defaultHeaders, ...options.headers };
223
- const response = await fetch('https://web.whatsapp.com/sw.js', {
278
+ const result = await axios_1.default.get(URL, {
224
279
  ...options,
225
- method: 'GET',
226
- headers
280
+ responseType: 'json'
227
281
  });
228
- if (!response.ok) {
229
- throw new Boom(`Failed to fetch sw.js: ${response.statusText}`, { statusCode: response.status });
230
- }
231
- const data = await response.text();
232
- const regex = /\\?"client_revision\\?":\s*(\d+)/;
233
- const match = data.match(regex);
234
- if (!match?.[1]) {
235
- return {
236
- version: baileysVersion,
237
- isLatest: false,
238
- error: {
239
- message: 'Could not find client revision in the fetched content'
240
- }
241
- };
242
- }
243
- const clientRevision = match[1];
244
282
  return {
245
- version: [2, 3000, +clientRevision],
283
+ version: result.data.version,
246
284
  isLatest: true
247
285
  };
248
286
  }
249
287
  catch (error) {
250
288
  return {
251
- version: baileysVersion,
289
+ version: baileys_version_json_1.version,
252
290
  isLatest: false,
253
291
  error
254
292
  };
255
293
  }
256
294
  };
295
+ exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
257
296
  /** unique message tag prefix for MD clients */
258
- export const generateMdTagPrefix = () => {
259
- const bytes = randomBytes(4);
297
+ const generateMdTagPrefix = () => {
298
+ const bytes = (0, crypto_1.randomBytes)(4);
260
299
  return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`;
261
300
  };
301
+ exports.generateMdTagPrefix = generateMdTagPrefix;
262
302
  const STATUS_MAP = {
263
- sender: proto.WebMessageInfo.Status.SERVER_ACK,
264
- played: proto.WebMessageInfo.Status.PLAYED,
265
- read: proto.WebMessageInfo.Status.READ,
266
- 'read-self': proto.WebMessageInfo.Status.READ
303
+ 'played': WAProto_1.proto.WebMessageInfo.Status.PLAYED,
304
+ 'read': WAProto_1.proto.WebMessageInfo.Status.READ,
305
+ 'read-self': WAProto_1.proto.WebMessageInfo.Status.READ
267
306
  };
268
307
  /**
269
308
  * Given a type of receipt, returns what the new status of the message should be
270
309
  * @param type type from receipt
271
310
  */
272
- export const getStatusFromReceiptType = (type) => {
311
+ const getStatusFromReceiptType = (type) => {
273
312
  const status = STATUS_MAP[type];
274
313
  if (typeof type === 'undefined') {
275
- return proto.WebMessageInfo.Status.DELIVERY_ACK;
314
+ return WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK;
276
315
  }
277
316
  return status;
278
317
  };
318
+ exports.getStatusFromReceiptType = getStatusFromReceiptType;
279
319
  const CODE_MAP = {
280
- conflict: DisconnectReason.connectionReplaced
320
+ conflict: Types_1.DisconnectReason.connectionReplaced
281
321
  };
282
322
  /**
283
323
  * Stream errors generally provide a reason, map that to a baileys DisconnectReason
284
324
  * @param reason the string reason given, eg. "conflict"
285
325
  */
286
- export const getErrorCodeFromStreamError = (node) => {
287
- const [reasonNode] = getAllBinaryNodeChildren(node);
288
- let reason = reasonNode?.tag || 'unknown';
289
- const statusCode = +(node.attrs.code || CODE_MAP[reason] || DisconnectReason.badSession);
290
- if (statusCode === DisconnectReason.restartRequired) {
326
+ const getErrorCodeFromStreamError = (node) => {
327
+ const [reasonNode] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
328
+ let reason = (reasonNode === null || reasonNode === void 0 ? void 0 : reasonNode.tag) || 'unknown';
329
+ const statusCode = +(node.attrs.code || CODE_MAP[reason] || Types_1.DisconnectReason.badSession);
330
+ if (statusCode === Types_1.DisconnectReason.restartRequired) {
291
331
  reason = 'restart required';
292
332
  }
293
333
  return {
@@ -295,7 +335,8 @@ export const getErrorCodeFromStreamError = (node) => {
295
335
  statusCode
296
336
  };
297
337
  };
298
- export const getCallStatusFromNode = ({ tag, attrs }) => {
338
+ exports.getErrorCodeFromStreamError = getErrorCodeFromStreamError;
339
+ const getCallStatusFromNode = ({ tag, attrs }) => {
299
340
  let status;
300
341
  switch (tag) {
301
342
  case 'offer':
@@ -307,8 +348,7 @@ export const getCallStatusFromNode = ({ tag, attrs }) => {
307
348
  status = 'timeout';
308
349
  }
309
350
  else {
310
- //fired when accepted/rejected/timeout/caller hangs up
311
- status = 'terminate';
351
+ status = 'reject';
312
352
  }
313
353
  break;
314
354
  case 'reject':
@@ -323,33 +363,33 @@ export const getCallStatusFromNode = ({ tag, attrs }) => {
323
363
  }
324
364
  return status;
325
365
  };
366
+ exports.getCallStatusFromNode = getCallStatusFromNode;
326
367
  const UNEXPECTED_SERVER_CODE_TEXT = 'Unexpected server response: ';
327
- export const getCodeFromWSError = (error) => {
368
+ const getCodeFromWSError = (error) => {
369
+ var _a, _b, _c;
328
370
  let statusCode = 500;
329
- if (error?.message?.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
330
- const code = +error?.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length);
371
+ if ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
372
+ const code = +(error === null || error === void 0 ? void 0 : error.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length));
331
373
  if (!Number.isNaN(code) && code >= 400) {
332
374
  statusCode = code;
333
375
  }
334
376
  }
335
- else if (
336
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
337
- error?.code?.startsWith('E') ||
338
- error?.message?.includes('timed out')) {
339
- // handle ETIMEOUT, ENOTFOUND etc
377
+ else if (((_b = error === null || error === void 0 ? void 0 : error.code) === null || _b === void 0 ? void 0 : _b.startsWith('E'))
378
+ || ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('timed out'))) { // handle ETIMEOUT, ENOTFOUND etc
340
379
  statusCode = 408;
341
380
  }
342
381
  return statusCode;
343
382
  };
383
+ exports.getCodeFromWSError = getCodeFromWSError;
344
384
  /**
345
385
  * Is the given platform WA business
346
386
  * @param platform AuthenticationCreds.platform
347
387
  */
348
- export const isWABusinessPlatform = (platform) => {
388
+ const isWABusinessPlatform = (platform) => {
349
389
  return platform === 'smbi' || platform === 'smba';
350
390
  };
351
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
352
- export function trimUndefined(obj) {
391
+ exports.isWABusinessPlatform = isWABusinessPlatform;
392
+ function trimUndefined(obj) {
353
393
  for (const key in obj) {
354
394
  if (typeof obj[key] === 'undefined') {
355
395
  delete obj[key];
@@ -357,13 +397,14 @@ export function trimUndefined(obj) {
357
397
  }
358
398
  return obj;
359
399
  }
400
+ exports.trimUndefined = trimUndefined;
360
401
  const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
361
- export function bytesToCrockford(buffer) {
402
+ function bytesToCrockford(buffer) {
362
403
  let value = 0;
363
404
  let bitCount = 0;
364
405
  const crockford = [];
365
- for (const element of buffer) {
366
- value = (value << 8) | (element & 0xff);
406
+ for (let i = 0; i < buffer.length; i++) {
407
+ value = (value << 8) | (buffer[i] & 0xff);
367
408
  bitCount += 8;
368
409
  while (bitCount >= 5) {
369
410
  crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
@@ -375,7 +416,8 @@ export function bytesToCrockford(buffer) {
375
416
  }
376
417
  return crockford.join('');
377
418
  }
378
- export function encodeNewsletterMessage(message) {
379
- return proto.Message.encode(message).finish();
419
+ exports.bytesToCrockford = bytesToCrockford;
420
+ const encodeNewsletterMessage = (message) => {
421
+ return WAProto_1.proto.Message.encode(message).finish()
380
422
  }
381
- //# sourceMappingURL=generics.js.map
423
+ exports.encodeNewsletterMessage = encodeNewsletterMessage;
@@ -1,19 +1,15 @@
1
- import { proto } from '../../WAProto/index.js';
2
- import type { Chat, Contact, WAMessage } from '../Types/index.js';
3
- export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: RequestInit) => Promise<proto.HistorySync>;
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { proto } from '../../WAProto';
3
+ import { Chat, Contact } from '../Types';
4
+ export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<proto.HistorySync>;
4
5
  export declare const processHistoryMessage: (item: proto.IHistorySync) => {
5
6
  chats: Chat[];
6
7
  contacts: Contact[];
7
- messages: WAMessage[];
8
- syncType: proto.HistorySync.HistorySyncType | null | undefined;
9
- progress: number | null | undefined;
8
+ messages: proto.IWebMessageInfo[];
10
9
  };
11
- export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: RequestInit) => Promise<{
10
+ export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<{
12
11
  chats: Chat[];
13
12
  contacts: Contact[];
14
- messages: WAMessage[];
15
- syncType: proto.HistorySync.HistorySyncType | null | undefined;
16
- progress: number | null | undefined;
13
+ messages: proto.IWebMessageInfo[];
17
14
  }>;
18
- export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification;
19
- //# sourceMappingURL=history.d.ts.map
15
+ export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined;