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.
- package/LICENSE +1 -1
- package/README.md +428 -0
- package/WAProto/index.js +130529 -45236
- package/engine-requirements.js +1 -1
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +9 -18
- package/lib/Defaults/index.js +136 -104
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -1
- package/lib/Signal/Group/ciphertext-message.js +5 -2
- package/lib/Signal/Group/group-session-builder.d.ts +3 -4
- package/lib/Signal/Group/group-session-builder.js +41 -7
- package/lib/Signal/Group/group_cipher.d.ts +4 -4
- package/lib/Signal/Group/group_cipher.js +51 -37
- package/lib/Signal/Group/index.d.ts +11 -12
- package/lib/Signal/Group/index.js +57 -12
- package/lib/Signal/Group/keyhelper.d.ts +1 -2
- package/lib/Signal/Group/keyhelper.js +44 -7
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +5 -2
- package/lib/Signal/Group/sender-chain-key.d.ts +2 -3
- package/lib/Signal/Group/sender-chain-key.js +15 -7
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +1 -2
- package/lib/Signal/Group/sender-key-distribution-message.js +11 -8
- package/lib/Signal/Group/sender-key-message.d.ts +1 -2
- package/lib/Signal/Group/sender-key-message.js +12 -9
- package/lib/Signal/Group/sender-key-name.d.ts +0 -1
- package/lib/Signal/Group/sender-key-name.js +5 -2
- package/lib/Signal/Group/sender-key-record.d.ts +2 -3
- package/lib/Signal/Group/sender-key-record.js +21 -9
- package/lib/Signal/Group/sender-key-state.d.ts +6 -7
- package/lib/Signal/Group/sender-key-state.js +42 -27
- package/lib/Signal/Group/sender-message-key.d.ts +0 -1
- package/lib/Signal/Group/sender-message-key.js +7 -4
- package/lib/Signal/libsignal.d.ts +3 -5
- package/lib/Signal/libsignal.js +90 -258
- package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +3 -2
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +3 -3
- package/lib/Socket/Client/index.js +19 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -2
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.d.ts +108 -125
- package/lib/Socket/business.js +43 -159
- package/lib/Socket/chats.d.ts +239 -70
- package/lib/Socket/chats.js +384 -363
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +484 -0
- package/lib/Socket/groups.d.ts +56 -78
- package/lib/Socket/groups.js +96 -106
- package/lib/Socket/index.d.ts +115 -173
- package/lib/Socket/index.js +10 -17
- package/lib/Socket/messages-recv.d.ts +79 -91
- package/lib/Socket/messages-recv.js +521 -639
- package/lib/Socket/messages-send.d.ts +91 -111
- package/lib/Socket/messages-send.js +438 -599
- package/lib/Socket/newsletter.d.ts +84 -97
- package/lib/Socket/newsletter.js +239 -145
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +18 -26
- package/lib/Socket/socket.js +230 -448
- package/lib/Socket/usync.d.ts +16 -17
- package/lib/Socket/usync.js +26 -19
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +10 -0
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-in-memory-store.js +427 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.d.ts +12 -13
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.d.ts +1 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.d.ts +13 -34
- package/lib/Types/Chat.js +4 -8
- package/lib/Types/Contact.d.ts +1 -6
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.d.ts +15 -60
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.d.ts +5 -17
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.d.ts +0 -12
- package/lib/Types/Label.js +5 -3
- package/lib/Types/LabelAssociation.d.ts +0 -1
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.d.ts +54 -84
- package/lib/Types/Message.js +9 -11
- package/lib/Types/Newsletter.d.ts +98 -130
- package/lib/Types/Newsletter.js +38 -31
- package/lib/Types/Product.d.ts +1 -2
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.d.ts +1 -20
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.d.ts +25 -47
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.d.ts +2 -14
- package/lib/Types/State.js +2 -13
- package/lib/Types/USync.d.ts +2 -3
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.d.ts +14 -22
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.d.ts +6 -7
- package/lib/Utils/auth-utils.js +148 -199
- package/lib/Utils/baileys-event-stream.d.ts +1 -2
- package/lib/Utils/baileys-event-stream.js +22 -15
- package/lib/Utils/business.d.ts +2 -3
- package/lib/Utils/business.js +69 -66
- package/lib/Utils/chat-utils.d.ts +22 -21
- package/lib/Utils/chat-utils.js +226 -260
- package/lib/Utils/crypto.d.ts +19 -19
- package/lib/Utils/crypto.js +86 -77
- package/lib/Utils/decode-wa-message.d.ts +8 -37
- package/lib/Utils/decode-wa-message.js +83 -164
- package/lib/Utils/event-buffer.d.ts +8 -7
- package/lib/Utils/event-buffer.js +76 -110
- package/lib/Utils/generics.d.ts +29 -27
- package/lib/Utils/generics.js +210 -168
- package/lib/Utils/history.d.ts +8 -12
- package/lib/Utils/history.js +46 -34
- package/lib/Utils/index.d.ts +17 -20
- package/lib/Utils/index.js +33 -20
- package/lib/Utils/link-preview.d.ts +5 -5
- package/lib/Utils/link-preview.js +22 -14
- package/lib/Utils/logger.d.ts +3 -11
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.d.ts +8 -9
- package/lib/Utils/lt-hash.js +28 -25
- package/lib/Utils/make-mutex.d.ts +2 -3
- package/lib/Utils/make-mutex.js +10 -7
- package/lib/Utils/messages-media.d.ts +44 -42
- package/lib/Utils/messages-media.js +475 -319
- package/lib/Utils/messages.d.ts +18 -17
- package/lib/Utils/messages.js +259 -383
- package/lib/Utils/noise-handler.d.ts +15 -14
- package/lib/Utils/noise-handler.js +38 -30
- package/lib/Utils/process-message.d.ts +13 -14
- package/lib/Utils/process-message.js +147 -239
- package/lib/Utils/signal.d.ts +5 -7
- package/lib/Utils/signal.js +72 -78
- package/lib/Utils/use-multi-file-auth-state.d.ts +2 -2
- package/lib/Utils/use-multi-file-auth-state.js +27 -29
- package/lib/Utils/validate-connection.d.ts +7 -7
- package/lib/Utils/validate-connection.js +106 -72
- package/lib/WABinary/constants.d.ts +27 -25
- package/lib/WABinary/constants.js +20 -1281
- package/lib/WABinary/decode.d.ts +5 -5
- package/lib/WABinary/decode.js +42 -28
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.js +154 -105
- package/lib/WABinary/generic-utils.d.ts +7 -5
- package/lib/WABinary/generic-utils.js +63 -56
- package/lib/WABinary/index.d.ts +5 -6
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.d.ts +8 -25
- package/lib/WABinary/jid-utils.js +40 -74
- package/lib/WABinary/types.d.ts +1 -2
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.d.ts +11 -3
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.d.ts +3 -5
- package/lib/WAM/constants.js +11958 -19461
- package/lib/WAM/encode.d.ts +3 -3
- package/lib/WAM/encode.js +22 -17
- package/lib/WAM/index.d.ts +3 -4
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -8
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -9
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -5
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +8 -13
- package/lib/WAUSync/Protocols/index.d.ts +4 -5
- package/lib/WAUSync/Protocols/index.js +20 -5
- package/lib/WAUSync/USyncQuery.d.ts +4 -5
- package/lib/WAUSync/USyncQuery.js +35 -40
- package/lib/WAUSync/USyncUser.d.ts +5 -6
- package/lib/WAUSync/USyncUser.js +5 -2
- package/lib/WAUSync/index.d.ts +3 -4
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.d.ts +9 -19
- package/lib/index.js +47 -24
- package/package.json +109 -99
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/WAProto.proto +0 -5519
- package/WAProto/fix-imports.js +0 -29
- package/WAProto/index.d.ts +0 -11969
- package/lib/Signal/lid-mapping.d.ts +0 -23
- package/lib/Signal/lid-mapping.js +0 -171
- package/lib/Socket/Client/types.js +0 -11
- package/lib/Socket/Client/websocket.js +0 -50
- package/lib/Socket/communities.d.ts +0 -244
- package/lib/Socket/communities.js +0 -431
- package/lib/Socket/mex.d.ts +0 -3
- package/lib/Socket/mex.js +0 -42
- package/lib/Types/Bussines.d.ts +0 -25
- package/lib/Types/Bussines.js +0 -2
- package/lib/Utils/browser-utils.d.ts +0 -4
- package/lib/Utils/browser-utils.js +0 -28
- package/lib/Utils/message-retry-manager.d.ts +0 -82
- package/lib/Utils/message-retry-manager.js +0 -149
- package/lib/Utils/pre-key-manager.d.ts +0 -28
- package/lib/Utils/pre-key-manager.js +0 -106
- /package/lib/{supun → supunmd} +0 -0
package/lib/Utils/generics.js
CHANGED
|
@@ -1,42 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
12
|
-
return { type: 'Buffer', data: Buffer.from(value
|
|
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
|
|
19
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
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
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
72
|
-
|
|
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
|
|
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) =>
|
|
86
|
-
setInterval: (newInterval) =>
|
|
113
|
+
setTask: (newTask) => task = newTask,
|
|
114
|
+
setInterval: (newInterval) => intervalMs = newInterval
|
|
87
115
|
};
|
|
88
116
|
};
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
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
|
-
})
|
|
157
|
+
})
|
|
158
|
+
.finally(cancel);
|
|
127
159
|
return p;
|
|
128
160
|
}
|
|
129
|
-
|
|
130
|
-
|
|
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
|
|
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 '
|
|
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
|
-
|
|
148
|
-
|
|
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
|
|
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 =
|
|
160
|
-
if (
|
|
193
|
+
listener = (update) => {
|
|
194
|
+
if (check(update)) {
|
|
161
195
|
resolve();
|
|
162
196
|
}
|
|
163
197
|
};
|
|
164
198
|
ev.on(event, listener);
|
|
165
|
-
})
|
|
199
|
+
})
|
|
200
|
+
.finally(() => {
|
|
166
201
|
ev.off(event, listener);
|
|
167
202
|
ev.off('connection.update', closeListener);
|
|
168
|
-
});
|
|
203
|
+
}));
|
|
169
204
|
};
|
|
170
205
|
}
|
|
171
|
-
|
|
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
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
275
|
+
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
276
|
+
const URL = 'https://raw.githubusercontent.com/kiuur/bails/master/src/Defaults/baileys-version.json';
|
|
216
277
|
try {
|
|
217
|
-
|
|
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
|
-
|
|
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:
|
|
283
|
+
version: result.data.version,
|
|
246
284
|
isLatest: true
|
|
247
285
|
};
|
|
248
286
|
}
|
|
249
287
|
catch (error) {
|
|
250
288
|
return {
|
|
251
|
-
version:
|
|
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
|
-
|
|
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
|
-
|
|
264
|
-
|
|
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
|
-
|
|
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
|
-
|
|
287
|
-
const [reasonNode] = getAllBinaryNodeChildren(node);
|
|
288
|
-
let reason = reasonNode
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
368
|
+
const getCodeFromWSError = (error) => {
|
|
369
|
+
var _a, _b, _c;
|
|
328
370
|
let statusCode = 500;
|
|
329
|
-
if (error
|
|
330
|
-
const code = +error
|
|
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
|
-
|
|
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
|
-
|
|
388
|
+
const isWABusinessPlatform = (platform) => {
|
|
349
389
|
return platform === 'smbi' || platform === 'smba';
|
|
350
390
|
};
|
|
351
|
-
|
|
352
|
-
|
|
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
|
-
|
|
402
|
+
function bytesToCrockford(buffer) {
|
|
362
403
|
let value = 0;
|
|
363
404
|
let bitCount = 0;
|
|
364
405
|
const crockford = [];
|
|
365
|
-
for (
|
|
366
|
-
value = (value << 8) | (
|
|
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
|
-
|
|
379
|
-
|
|
419
|
+
exports.bytesToCrockford = bytesToCrockford;
|
|
420
|
+
const encodeNewsletterMessage = (message) => {
|
|
421
|
+
return WAProto_1.proto.Message.encode(message).finish()
|
|
380
422
|
}
|
|
381
|
-
|
|
423
|
+
exports.encodeNewsletterMessage = encodeNewsletterMessage;
|
package/lib/Utils/history.d.ts
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
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:
|
|
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:
|
|
10
|
+
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<{
|
|
12
11
|
chats: Chat[];
|
|
13
12
|
contacts: Contact[];
|
|
14
|
-
messages:
|
|
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;
|