naya-flore 4.7.2 → 4.7.3
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/README.md +0 -104
- package/WAProto/WAProto.proto +89 -1195
- package/WAProto/index.d.ts +1256 -13195
- package/WAProto/index.js +11405 -32544
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +0 -231
- package/lib/Defaults/index.js +102 -92
- package/lib/Defaults/phonenumber-mcc.json +221 -221
- package/lib/Signal/libsignal.js +9 -18
- package/lib/Socket/Client/abstract-socket-client.d.ts +2 -0
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.js +3 -2
- package/lib/Socket/Client/mobile-socket-client.d.ts +1 -0
- package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
- package/lib/Socket/Client/{websocket.js → web-socket-client.js} +2 -2
- package/lib/Socket/business.d.ts +43 -42
- package/lib/Socket/chats.d.ts +8 -9
- package/lib/Socket/chats.js +34 -41
- package/lib/Socket/groups.d.ts +7 -7
- package/lib/Socket/groups.js +4 -2
- package/lib/Socket/index.d.ts +52 -51
- package/lib/Socket/messages-recv.d.ts +42 -41
- package/lib/Socket/messages-recv.js +127 -190
- package/lib/Socket/messages-send.d.ts +9 -16
- package/lib/Socket/messages-send.js +316 -467
- package/lib/Socket/newsletter.d.ts +28 -26
- package/lib/Socket/newsletter.js +3 -3
- package/lib/Socket/registration.d.ts +52 -49
- package/lib/Socket/registration.js +7 -7
- package/lib/Socket/socket.d.ts +0 -1
- package/lib/Socket/socket.js +23 -49
- package/lib/Socket/usync.d.ts +10 -11
- package/lib/Store/index.d.ts +2 -2
- package/lib/Store/index.js +2 -2
- package/lib/Store/make-cache-manager-store.d.ts +0 -1
- package/lib/Store/make-in-memory-store.js +1 -5
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Types/Auth.d.ts +1 -0
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +7 -12
- package/lib/Types/Events.d.ts +2 -17
- package/lib/Types/GroupMetadata.d.ts +2 -3
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +10 -170
- package/lib/Types/Newsletter.js +3 -3
- package/lib/Types/Socket.d.ts +4 -7
- package/lib/Types/index.d.ts +0 -9
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.js +3 -3
- package/lib/Utils/business.d.ts +1 -1
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +12 -11
- package/lib/Utils/chat-utils.js +26 -42
- package/lib/Utils/crypto.d.ts +16 -15
- package/lib/Utils/crypto.js +23 -35
- package/lib/Utils/decode-wa-message.d.ts +0 -17
- package/lib/Utils/decode-wa-message.js +15 -43
- package/lib/Utils/generics.d.ts +17 -13
- package/lib/Utils/generics.js +15 -25
- package/lib/Utils/history.d.ts +2 -6
- package/lib/Utils/history.js +6 -4
- package/lib/Utils/logger.d.ts +3 -1
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +28 -25
- package/lib/Utils/messages-media.js +47 -38
- package/lib/Utils/messages.js +41 -454
- package/lib/Utils/noise-handler.d.ts +5 -4
- package/lib/Utils/process-message.js +2 -2
- package/lib/Utils/signal.d.ts +1 -2
- package/lib/Utils/signal.js +19 -11
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +3 -11
- package/lib/Utils/validate-connection.d.ts +1 -1
- package/lib/Utils/validate-connection.js +1 -1
- package/lib/WABinary/decode.d.ts +2 -1
- package/lib/WABinary/decode.js +7 -17
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +17 -33
- package/lib/WABinary/generic-utils.d.ts +3 -2
- package/lib/WABinary/generic-utils.js +2 -2
- package/lib/WABinary/jid-utils.d.ts +1 -1
- package/lib/WAM/BinaryInfo.d.ts +11 -2
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/USyncQuery.d.ts +2 -0
- package/lib/WAUSync/USyncQuery.js +10 -0
- package/lib/WAUSync/USyncUser.d.ts +2 -0
- package/lib/WAUSync/USyncUser.js +4 -0
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/package.json +19 -32
- package/lib/Socket/Client/types.d.ts +0 -17
- package/lib/Socket/Client/types.js +0 -13
package/lib/Utils/generics.js
CHANGED
@@ -1,13 +1,9 @@
|
|
1
|
-
"use strict";
|
1
|
+
"use strict";
|
2
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.generateMessageID = exports.generateMessageIDV2 = 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.
|
7
|
-
exports.promiseTimeout = promiseTimeout;
|
8
|
-
exports.bindWaitForEvent = bindWaitForEvent;
|
9
|
-
exports.trimUndefined = trimUndefined;
|
10
|
-
exports.bytesToCrockford = bytesToCrockford;
|
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;
|
11
7
|
const boom_1 = require("@hapi/boom");
|
12
8
|
const axios_1 = __importDefault(require("axios"));
|
13
9
|
const crypto_1 = require("crypto");
|
@@ -16,13 +12,6 @@ const WAProto_1 = require("../../WAProto");
|
|
16
12
|
const baileys_version_json_1 = require("../Defaults/baileys-version.json");
|
17
13
|
const Types_1 = require("../Types");
|
18
14
|
const WABinary_1 = require("../WABinary");
|
19
|
-
const COMPANION_PLATFORM_MAP = {
|
20
|
-
'Chrome': '49',
|
21
|
-
'Edge': '50',
|
22
|
-
'Firefox': '51',
|
23
|
-
'Opera': '53',
|
24
|
-
'Safari': '54'
|
25
|
-
};
|
26
15
|
const PLATFORM_MAP = {
|
27
16
|
'aix': 'AIX',
|
28
17
|
'darwin': 'Mac OS',
|
@@ -37,14 +26,12 @@ exports.Browsers = {
|
|
37
26
|
macOS: (browser) => ['Mac OS', browser, '14.4.1'],
|
38
27
|
baileys: (browser) => ['Baileys', browser, '6.5.0'],
|
39
28
|
windows: (browser) => ['Windows', browser, '10.0.22631'],
|
40
|
-
iOS: (browser) => ['iOS', browser, '18.2'],
|
41
|
-
linux: (browser) => ['Linux', browser, '6.12.6'],
|
42
|
-
/** The appropriate browser based on your OS & release */
|
43
29
|
appropriate: (browser) => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
44
30
|
};
|
31
|
+
|
45
32
|
const getPlatformId = (browser) => {
|
46
33
|
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
47
|
-
return platformType ? platformType.toString() : '1' //chrome
|
34
|
+
return platformType ? platformType.toString() : '1'; //chrome
|
48
35
|
};
|
49
36
|
exports.getPlatformId = getPlatformId;
|
50
37
|
exports.BufferJSON = {
|
@@ -167,6 +154,7 @@ async function promiseTimeout(ms, promise) {
|
|
167
154
|
.finally(cancel);
|
168
155
|
return p;
|
169
156
|
}
|
157
|
+
exports.promiseTimeout = promiseTimeout;
|
170
158
|
const generateMessageIDV2 = (userId) => {
|
171
159
|
const data = Buffer.alloc(8 + 20 + 16);
|
172
160
|
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
@@ -180,11 +168,11 @@ const generateMessageIDV2 = (userId) => {
|
|
180
168
|
const random = (0, crypto_1.randomBytes)(16);
|
181
169
|
random.copy(data, 28);
|
182
170
|
const hash = (0, crypto_1.createHash)('sha256').update(data).digest();
|
183
|
-
return '
|
171
|
+
return '3EB0' + hash.toString('hex').toUpperCase().substring(0, 18);
|
184
172
|
};
|
185
173
|
exports.generateMessageIDV2 = generateMessageIDV2;
|
186
174
|
// generate a random ID to attach to a message
|
187
|
-
const generateMessageID = () => '
|
175
|
+
const generateMessageID = () => 'SH3NN-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
|
188
176
|
exports.generateMessageID = generateMessageID;
|
189
177
|
function bindWaitForEvent(ev, event) {
|
190
178
|
return async (check, timeoutMs) => {
|
@@ -211,6 +199,7 @@ function bindWaitForEvent(ev, event) {
|
|
211
199
|
}));
|
212
200
|
};
|
213
201
|
}
|
202
|
+
exports.bindWaitForEvent = bindWaitForEvent;
|
214
203
|
const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
|
215
204
|
exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
216
205
|
const printQRIfNecessaryListener = (ev, logger) => {
|
@@ -231,7 +220,7 @@ exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
|
|
231
220
|
* Use to ensure your WA connection is always on the latest version
|
232
221
|
*/
|
233
222
|
const fetchLatestBaileysVersion = async (options = {}) => {
|
234
|
-
const URL = 'https://raw.githubusercontent.com/
|
223
|
+
const URL = 'https://raw.githubusercontent.com/kiuur/bails/master/src/Defaults/baileys-version.json';
|
235
224
|
try {
|
236
225
|
const result = await axios_1.default.get(URL, {
|
237
226
|
...options,
|
@@ -331,8 +320,7 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
331
320
|
status = 'timeout';
|
332
321
|
}
|
333
322
|
else {
|
334
|
-
|
335
|
-
status = 'terminate';
|
323
|
+
status = 'reject';
|
336
324
|
}
|
337
325
|
break;
|
338
326
|
case 'reject':
|
@@ -359,7 +347,7 @@ const getCodeFromWSError = (error) => {
|
|
359
347
|
}
|
360
348
|
}
|
361
349
|
else if (((_b = error === null || error === void 0 ? void 0 : error.code) === null || _b === void 0 ? void 0 : _b.startsWith('E'))
|
362
|
-
|| ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('timed out'))) {
|
350
|
+
|| ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('timed out'))) { // handle ETIMEOUT, ENOTFOUND etc
|
363
351
|
statusCode = 408;
|
364
352
|
}
|
365
353
|
return statusCode;
|
@@ -381,6 +369,7 @@ function trimUndefined(obj) {
|
|
381
369
|
}
|
382
370
|
return obj;
|
383
371
|
}
|
372
|
+
exports.trimUndefined = trimUndefined;
|
384
373
|
const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
|
385
374
|
function bytesToCrockford(buffer) {
|
386
375
|
let value = 0;
|
@@ -397,5 +386,6 @@ function bytesToCrockford(buffer) {
|
|
397
386
|
if (bitCount > 0) {
|
398
387
|
crockford.push(CROCKFORD_CHARACTERS.charAt((value << (5 - bitCount)) & 31));
|
399
388
|
}
|
400
|
-
return
|
401
|
-
}
|
389
|
+
return crockford.join('');
|
390
|
+
}
|
391
|
+
exports.bytesToCrockford = bytesToCrockford;
|
package/lib/Utils/history.d.ts
CHANGED
@@ -1,19 +1,15 @@
|
|
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<
|
4
|
+
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => 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;
|
11
9
|
};
|
12
|
-
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<
|
10
|
+
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<{
|
13
11
|
chats: Chat[];
|
14
12
|
contacts: Contact[];
|
15
13
|
messages: proto.IWebMessageInfo[];
|
16
|
-
syncType: proto.HistorySync.HistorySyncType;
|
17
|
-
progress: number | null | undefined;
|
18
14
|
}>;
|
19
15
|
export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined;
|
package/lib/Utils/history.js
CHANGED
@@ -32,9 +32,13 @@ 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:
|
36
35
|
for (const chat of item.conversations) {
|
37
|
-
contacts.push({
|
36
|
+
contacts.push({
|
37
|
+
id: chat.id,
|
38
|
+
name: chat.name || undefined,
|
39
|
+
lid: chat.lidJid || undefined,
|
40
|
+
jid: (0, WABinary_1.isJidUser)(chat.id) ? chat.id : undefined
|
41
|
+
});
|
38
42
|
const msgs = chat.messages || [];
|
39
43
|
delete chat.messages;
|
40
44
|
delete chat.archived;
|
@@ -75,8 +79,6 @@ const processHistoryMessage = (item) => {
|
|
75
79
|
chats,
|
76
80
|
contacts,
|
77
81
|
messages,
|
78
|
-
syncType: item.syncType,
|
79
|
-
progress: item.progress
|
80
82
|
};
|
81
83
|
};
|
82
84
|
exports.processHistoryMessage = processHistoryMessage;
|
package/lib/Utils/logger.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
export declare const makeMutex: () => {
|
2
|
-
mutex<T>(code: () =>
|
2
|
+
mutex<T>(code: () => T | Promise<T>): Promise<T>;
|
3
3
|
};
|
4
4
|
export type Mutex = ReturnType<typeof makeMutex>;
|
5
5
|
export declare const makeKeyedMutex: () => {
|
6
|
-
mutex<T>(key: string, task: () =>
|
6
|
+
mutex<T>(key: string, task: () => T | Promise<T>): Promise<T>;
|
7
7
|
};
|
@@ -1,7 +1,10 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
3
|
+
/// <reference types="node" />
|
1
4
|
import { Boom } from '@hapi/boom';
|
2
5
|
import { AxiosRequestConfig } from 'axios';
|
3
6
|
import type { Logger } from 'pino';
|
4
|
-
import { Readable } from 'stream';
|
7
|
+
import { Readable, Transform } from 'stream';
|
5
8
|
import { URL } from 'url';
|
6
9
|
import { proto } from '../../WAProto';
|
7
10
|
import { DownloadableMessage, MediaConnInfo, MediaDecryptionKeyInfo, MediaType, SocketConfig, WAMediaUpload, WAMediaUploadFunction, WAMessageContent } from '../Types';
|
@@ -10,10 +13,10 @@ export declare const hkdfInfoKey: (type: MediaType) => string;
|
|
10
13
|
/** generates all the keys required to encrypt/decrypt & sign a media message */
|
11
14
|
export declare function getMediaKeys(buffer: Uint8Array | string | null | undefined, mediaType: MediaType): MediaDecryptionKeyInfo;
|
12
15
|
export declare const extractImageThumb: (bufferOrFilePath: Readable | Buffer | string, width?: number) => Promise<{
|
13
|
-
buffer:
|
16
|
+
buffer: Buffer;
|
14
17
|
original: {
|
15
|
-
width:
|
16
|
-
height:
|
18
|
+
width: number | undefined;
|
19
|
+
height: number | undefined;
|
17
20
|
};
|
18
21
|
}>;
|
19
22
|
export declare const encodeBase64EncodedStringForUpload: (b64: string) => string;
|
@@ -21,25 +24,25 @@ export declare const generateProfilePicture: (mediaUpload: WAMediaUpload) => Pro
|
|
21
24
|
img: Buffer;
|
22
25
|
}>;
|
23
26
|
/** gets the SHA256 of the given media message */
|
24
|
-
export declare const mediaMessageSHA256B64: (message: WAMessageContent) =>
|
25
|
-
export declare function getAudioDuration(buffer: Buffer | string | Readable): Promise<
|
27
|
+
export declare const mediaMessageSHA256B64: (message: WAMessageContent) => string | null | undefined;
|
28
|
+
export declare function getAudioDuration(buffer: Buffer | string | Readable): Promise<number | undefined>;
|
26
29
|
/**
|
27
30
|
referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
|
28
31
|
*/
|
29
|
-
export declare function getAudioWaveform(buffer: Buffer | string | Readable, logger?: Logger): Promise<Uint8Array
|
30
|
-
export declare const toReadable: (buffer: Buffer) =>
|
31
|
-
export declare const toBuffer: (stream: Readable) => Promise<
|
32
|
+
export declare function getAudioWaveform(buffer: Buffer | string | Readable, logger?: Logger): Promise<Uint8Array | undefined>;
|
33
|
+
export declare const toReadable: (buffer: Buffer) => Readable;
|
34
|
+
export declare const toBuffer: (stream: Readable) => Promise<Buffer>;
|
32
35
|
export declare const getStream: (item: WAMediaUpload, opts?: AxiosRequestConfig) => Promise<{
|
33
|
-
readonly stream:
|
36
|
+
readonly stream: Readable;
|
34
37
|
readonly type: "buffer";
|
35
38
|
} | {
|
36
|
-
readonly stream:
|
39
|
+
readonly stream: Readable;
|
37
40
|
readonly type: "readable";
|
38
41
|
} | {
|
39
42
|
readonly stream: Readable;
|
40
43
|
readonly type: "remote";
|
41
44
|
} | {
|
42
|
-
readonly stream:
|
45
|
+
readonly stream: import("fs").ReadStream;
|
43
46
|
readonly type: "file";
|
44
47
|
}>;
|
45
48
|
/** generates a thumbnail for a given media, if required */
|
@@ -62,20 +65,20 @@ type EncryptedStreamOptions = {
|
|
62
65
|
};
|
63
66
|
export declare const prepareStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
|
64
67
|
mediaKey: undefined;
|
65
|
-
encWriteStream:
|
66
|
-
fileLength:
|
67
|
-
fileSha256:
|
68
|
+
encWriteStream: Buffer;
|
69
|
+
fileLength: number;
|
70
|
+
fileSha256: Buffer;
|
68
71
|
fileEncSha256: undefined;
|
69
72
|
bodyPath: string | undefined;
|
70
73
|
didSaveToTmpPath: boolean;
|
71
74
|
}>;
|
72
75
|
export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
|
73
|
-
mediaKey:
|
74
|
-
encWriteStream:
|
76
|
+
mediaKey: Buffer;
|
77
|
+
encWriteStream: Readable;
|
75
78
|
bodyPath: string | undefined;
|
76
|
-
mac:
|
77
|
-
fileEncSha256:
|
78
|
-
fileSha256:
|
79
|
+
mac: Buffer;
|
80
|
+
fileEncSha256: Buffer;
|
81
|
+
fileSha256: Buffer;
|
79
82
|
fileLength: number;
|
80
83
|
didSaveToTmpPath: boolean;
|
81
84
|
}>;
|
@@ -85,12 +88,12 @@ export type MediaDownloadOptions = {
|
|
85
88
|
options?: AxiosRequestConfig<any>;
|
86
89
|
};
|
87
90
|
export declare const getUrlFromDirectPath: (directPath: string) => string;
|
88
|
-
export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<
|
91
|
+
export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<Transform>;
|
89
92
|
/**
|
90
93
|
* Decrypts and downloads an AES256-CBC encrypted file given the keys.
|
91
94
|
* Assumes the SHA256 of the plaintext is appended to the end of the ciphertext
|
92
95
|
* */
|
93
|
-
export declare const downloadEncryptedContent: (downloadUrl: string, { cipherKey, iv }: MediaDecryptionKeyInfo, { startByte, endByte, options }?: MediaDownloadOptions) => Promise<
|
96
|
+
export declare const downloadEncryptedContent: (downloadUrl: string, { cipherKey, iv }: MediaDecryptionKeyInfo, { startByte, endByte, options }?: MediaDownloadOptions) => Promise<Transform>;
|
94
97
|
export declare function extensionForMediaMessage(message: WAMessageContent): string;
|
95
98
|
export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logger, options }: SocketConfig, refreshMediaConn: (force: boolean) => Promise<MediaConnInfo>) => WAMediaUploadFunction;
|
96
99
|
/**
|
@@ -98,12 +101,12 @@ export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logg
|
|
98
101
|
*/
|
99
102
|
export declare const encryptMediaRetryRequest: (key: proto.IMessageKey, mediaKey: Buffer | Uint8Array, meId: string) => BinaryNode;
|
100
103
|
export declare const decodeMediaRetryNode: (node: BinaryNode) => {
|
101
|
-
key:
|
104
|
+
key: proto.IMessageKey;
|
102
105
|
media?: {
|
103
106
|
ciphertext: Uint8Array;
|
104
107
|
iv: Uint8Array;
|
105
|
-
};
|
106
|
-
error?: Boom;
|
108
|
+
} | undefined;
|
109
|
+
error?: Boom<any> | undefined;
|
107
110
|
};
|
108
111
|
export declare const decryptMediaRetryData: ({ ciphertext, iv }: {
|
109
112
|
ciphertext: Uint8Array;
|
@@ -15,30 +15,15 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
15
15
|
}) : function(o, v) {
|
16
16
|
o["default"] = v;
|
17
17
|
});
|
18
|
-
var __importStar = (this && this.__importStar) ||
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
return ownKeys(o);
|
26
|
-
};
|
27
|
-
return function (mod) {
|
28
|
-
if (mod && mod.__esModule) return mod;
|
29
|
-
var result = {};
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
-
__setModuleDefault(result, mod);
|
32
|
-
return result;
|
33
|
-
};
|
34
|
-
})();
|
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
|
+
};
|
35
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
36
|
-
exports.getStatusCodeForMediaRetry = exports.decryptMediaRetryData = exports.decodeMediaRetryNode = exports.encryptMediaRetryRequest = exports.getWAUploadToServer = exports.downloadEncryptedContent = exports.downloadContentFromMessage = exports.getUrlFromDirectPath = exports.encryptedStream = exports.prepareStream = exports.getHttpStream = exports.getStream = exports.toBuffer = exports.toReadable = exports.mediaMessageSHA256B64 = exports.generateProfilePicture = exports.encodeBase64EncodedStringForUpload = exports.extractImageThumb = exports.hkdfInfoKey = void 0;
|
37
|
-
exports.getMediaKeys = getMediaKeys;
|
38
|
-
exports.getAudioDuration = getAudioDuration;
|
39
|
-
exports.getAudioWaveform = getAudioWaveform;
|
40
|
-
exports.generateThumbnail = generateThumbnail;
|
41
|
-
exports.extensionForMediaMessage = extensionForMediaMessage;
|
26
|
+
exports.getStatusCodeForMediaRetry = exports.decryptMediaRetryData = exports.decodeMediaRetryNode = exports.encryptMediaRetryRequest = exports.getWAUploadToServer = exports.extensionForMediaMessage = exports.downloadEncryptedContent = exports.downloadContentFromMessage = exports.getUrlFromDirectPath = exports.encryptedStream = exports.prepareStream = exports.getHttpStream = exports.generateThumbnail = exports.getStream = exports.toBuffer = exports.toReadable = exports.getAudioWaveform = exports.getAudioDuration = exports.mediaMessageSHA256B64 = exports.generateProfilePicture = exports.encodeBase64EncodedStringForUpload = exports.extractImageThumb = exports.getMediaKeys = exports.hkdfInfoKey = void 0;
|
42
27
|
const boom_1 = require("@hapi/boom");
|
43
28
|
const child_process_1 = require("child_process");
|
44
29
|
const Crypto = __importStar(require("crypto"));
|
@@ -96,6 +81,7 @@ function getMediaKeys(buffer, mediaType) {
|
|
96
81
|
macKey: expandedMediaKey.slice(48, 80),
|
97
82
|
};
|
98
83
|
}
|
84
|
+
exports.getMediaKeys = getMediaKeys;
|
99
85
|
/** Extracts video thumb using FFMPEG */
|
100
86
|
const extractVideoThumb = async (path, destPath, time, size) => new Promise((resolve, reject) => {
|
101
87
|
const cmd = `ffmpeg -ss ${time} -i ${path} -y -vf scale=${size.width}:-1 -vframes 1 -f image2 ${destPath}`;
|
@@ -156,23 +142,42 @@ const encodeBase64EncodedStringForUpload = (b64) => (encodeURIComponent(b64
|
|
156
142
|
.replace(/\=+$/, '')));
|
157
143
|
exports.encodeBase64EncodedStringForUpload = encodeBase64EncodedStringForUpload;
|
158
144
|
const generateProfilePicture = async (mediaUpload) => {
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
145
|
+
var _a, _b;
|
146
|
+
let bufferOrFilePath;
|
147
|
+
if (Buffer.isBuffer(mediaUpload)) {
|
148
|
+
bufferOrFilePath = mediaUpload;
|
149
|
+
}
|
150
|
+
else if ('url' in mediaUpload) {
|
151
|
+
bufferOrFilePath = mediaUpload.url.toString();
|
152
|
+
}
|
153
|
+
else {
|
154
|
+
bufferOrFilePath = await (0, exports.toBuffer)(mediaUpload.stream);
|
155
|
+
}
|
156
|
+
const lib = await getImageProcessingLibrary();
|
164
157
|
let img;
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
158
|
+
if ('sharp' in lib && typeof ((_a = lib.sharp) === null || _a === void 0 ? void 0 : _a.default) === 'function') {
|
159
|
+
img = lib.sharp.default(bufferOrFilePath)
|
160
|
+
.resize(640, 640)
|
161
|
+
.jpeg({
|
162
|
+
quality: 50,
|
163
|
+
})
|
164
|
+
.toBuffer();
|
165
|
+
}
|
166
|
+
else if ('jimp' in lib && typeof ((_b = lib.jimp) === null || _b === void 0 ? void 0 : _b.read) === 'function') {
|
167
|
+
const { read, MIME_JPEG, RESIZE_BILINEAR } = lib.jimp;
|
168
|
+
const jimp = await read(bufferOrFilePath);
|
169
|
+
const min = Math.min(jimp.getWidth(), jimp.getHeight());
|
170
|
+
const cropped = jimp.crop(0, 0, min, min);
|
171
|
+
img = cropped
|
172
|
+
.quality(50)
|
173
|
+
.resize(640, 640, RESIZE_BILINEAR)
|
174
|
+
.getBufferAsync(MIME_JPEG);
|
175
|
+
}
|
176
|
+
else {
|
177
|
+
throw new boom_1.Boom('No image processing library available');
|
178
|
+
}
|
174
179
|
return {
|
175
|
-
img: await img
|
180
|
+
img: await img,
|
176
181
|
};
|
177
182
|
};
|
178
183
|
exports.generateProfilePicture = generateProfilePicture;
|
@@ -202,6 +207,7 @@ async function getAudioDuration(buffer) {
|
|
202
207
|
}
|
203
208
|
return metadata.format.duration;
|
204
209
|
}
|
210
|
+
exports.getAudioDuration = getAudioDuration;
|
205
211
|
/**
|
206
212
|
referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
|
207
213
|
*/
|
@@ -243,6 +249,7 @@ async function getAudioWaveform(buffer, logger) {
|
|
243
249
|
logger === null || logger === void 0 ? void 0 : logger.debug('Failed to generate waveform: ' + e);
|
244
250
|
}
|
245
251
|
}
|
252
|
+
exports.getAudioWaveform = getAudioWaveform;
|
246
253
|
const toReadable = (buffer) => {
|
247
254
|
const readable = new stream_1.Readable({ read: () => { } });
|
248
255
|
readable.push(buffer);
|
@@ -304,6 +311,7 @@ async function generateThumbnail(file, mediaType, options) {
|
|
304
311
|
originalImageDimensions
|
305
312
|
};
|
306
313
|
}
|
314
|
+
exports.generateThumbnail = generateThumbnail;
|
307
315
|
const getHttpStream = async (url, options = {}) => {
|
308
316
|
const { default: axios } = await import('axios');
|
309
317
|
const fetched = await axios.get(url.toString(), { ...options, responseType: 'stream' });
|
@@ -557,6 +565,7 @@ function extensionForMediaMessage(message) {
|
|
557
565
|
}
|
558
566
|
return extension;
|
559
567
|
}
|
568
|
+
exports.extensionForMediaMessage = extensionForMediaMessage;
|
560
569
|
const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
|
561
570
|
return async (stream, { mediaType, fileEncSha256B64, newsletter, timeoutMs }) => {
|
562
571
|
var _a, _b;
|