@vinzsocket/baileys 2.8.30 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/WAProto/fix-imports.js +7 -16
- package/WAProto/index.js +1 -37306
- package/lib/Defaults/index.js +37 -33
- package/lib/Signal/Group/ciphertext-message.js +6 -2
- package/lib/Signal/Group/group-session-builder.js +12 -7
- package/lib/Signal/Group/group_cipher.js +18 -13
- package/lib/Signal/Group/index.js +77 -12
- package/lib/Signal/Group/keyhelper.js +15 -8
- package/lib/Signal/Group/queue-job.js +7 -2
- package/lib/Signal/Group/sender-chain-key.js +11 -6
- package/lib/Signal/Group/sender-key-distribution-message.js +10 -6
- package/lib/Signal/Group/sender-key-message.js +14 -9
- package/lib/Signal/Group/sender-key-name.js +6 -2
- package/lib/Signal/Group/sender-key-record.js +13 -9
- package/lib/Signal/Group/sender-key-state.js +10 -6
- package/lib/Signal/Group/sender-message-key.js +9 -4
- package/lib/Signal/libsignal.js +34 -28
- package/lib/Signal/lid-mapping.js +24 -19
- package/lib/Socket/Client/index.js +25 -3
- package/lib/Socket/Client/types.js +8 -4
- package/lib/Socket/Client/websocket.js +16 -11
- package/lib/Socket/business.js +38 -34
- package/lib/Socket/chats.js +100 -95
- package/lib/Socket/communities.js +55 -49
- package/lib/Socket/groups.js +56 -51
- package/lib/Socket/index.js +9 -6
- package/lib/Socket/messages-recv.js +150 -145
- package/lib/Socket/messages-send.js +109 -104
- package/lib/Socket/mex.js +12 -8
- package/lib/Socket/newsletter.js +27 -23
- package/lib/Socket/socket.js +111 -107
- package/lib/Store/index.js +47 -4
- package/lib/Store/make-cache-manager-store.js +17 -11
- package/lib/Store/make-in-memory-store.js +31 -29
- package/lib/Store/make-ordered-dictionary.js +7 -2
- package/lib/Store/object-repository.js +7 -2
- package/lib/Types/Auth.js +3 -2
- package/lib/Types/Bussines.js +3 -2
- package/lib/Types/Call.js +3 -2
- package/lib/Types/Chat.js +5 -2
- package/lib/Types/Contact.js +3 -2
- package/lib/Types/Events.js +1 -2
- package/lib/Types/GroupMetadata.js +3 -2
- package/lib/Types/Label.js +6 -3
- package/lib/Types/LabelAssociation.js +6 -3
- package/lib/Types/Message.js +16 -7
- package/lib/Types/Newsletter.js +8 -5
- package/lib/Types/Product.js +3 -2
- package/lib/Types/Signal.js +1 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +7 -4
- package/lib/Types/USync.js +1 -2
- package/lib/Types/index.js +153 -15
- package/lib/Utils/auth-utils.js +32 -25
- package/lib/Utils/baileys-event-stream.js +21 -15
- package/lib/Utils/business.js +71 -61
- package/lib/Utils/chat-utils.js +91 -77
- package/lib/Utils/crypto.js +54 -32
- package/lib/Utils/decode-wa-message.js +46 -39
- package/lib/Utils/event-buffer.js +24 -19
- package/lib/Utils/extended-messages.js +14 -9
- package/lib/Utils/generics.js +100 -64
- package/lib/Utils/history.js +30 -23
- package/lib/Utils/index.js +234 -22
- package/lib/Utils/lid-resolver.js +12 -5
- package/lib/Utils/link-preview.js +11 -7
- package/lib/Utils/logger.js +8 -4
- package/lib/Utils/lt-hash.js +8 -5
- package/lib/Utils/make-mutex.js +8 -3
- package/lib/Utils/mention.js +12 -4
- package/lib/Utils/message-retry-manager.js +10 -6
- package/lib/Utils/messages-media.js +127 -95
- package/lib/Utils/messages.js +122 -98
- package/lib/Utils/noise-handler.js +25 -21
- package/lib/Utils/process-message.js +72 -63
- package/lib/Utils/signal.js +45 -33
- package/lib/Utils/use-multi-file-auth-state.js +24 -20
- package/lib/Utils/validate-connection.js +54 -47
- package/lib/WABinary/constants.js +9 -6
- package/lib/WABinary/decode.js +17 -10
- package/lib/WABinary/encode.js +11 -6
- package/lib/WABinary/generic-utils.js +31 -17
- package/lib/WABinary/index.js +58 -6
- package/lib/WABinary/jid-utils.js +36 -20
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +6 -2
- package/lib/WAM/constants.js +1 -1
- package/lib/WAM/encode.js +16 -12
- package/lib/WAM/index.js +36 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +9 -5
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +10 -6
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +8 -4
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +8 -4
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +9 -4
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +23 -19
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +6 -2
- package/lib/WAUSync/Protocols/index.js +58 -6
- package/lib/WAUSync/USyncQuery.js +21 -17
- package/lib/WAUSync/USyncUser.js +6 -2
- package/lib/WAUSync/index.js +36 -4
- package/lib/index.js +112 -12
- package/package.json +8 -6
package/lib/Utils/auth-utils.js
CHANGED
|
@@ -1,25 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
Object.defineProperty(exports, "__esModule", {
|
|
2
|
+
value: true
|
|
3
|
+
});
|
|
4
|
+
exports.initAuthCreds = exports.addTransactionCapability = void 0;
|
|
5
|
+
exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
|
|
6
|
+
var _nodeCache = _interopRequireDefault(require("@cacheable/node-cache"));
|
|
7
|
+
var _asyncMutex = require("async-mutex");
|
|
8
|
+
var _crypto = require("crypto");
|
|
9
|
+
var _lruCache = require("lru-cache");
|
|
10
|
+
var _index = require("../Defaults/index.js");
|
|
11
|
+
var _crypto2 = require("./crypto.js");
|
|
12
|
+
var _generics = require("./generics.js");
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
14
|
/**
|
|
9
15
|
* Adds caching capability to a SignalKeyStore
|
|
10
16
|
* @param store the store to add caching to
|
|
11
17
|
* @param logger to log trace events
|
|
12
18
|
* @param _cache cache store to use
|
|
13
19
|
*/
|
|
14
|
-
|
|
15
|
-
const cache = _cache || new
|
|
16
|
-
stdTTL: DEFAULT_CACHE_TTLS.SIGNAL_STORE,
|
|
20
|
+
function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
21
|
+
const cache = _cache || new _nodeCache.default({
|
|
22
|
+
stdTTL: _index.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
|
|
17
23
|
// 5 minutes
|
|
18
24
|
useClones: false,
|
|
19
25
|
deleteOnExpire: true
|
|
20
26
|
});
|
|
21
27
|
// Mutex for protecting cache operations
|
|
22
|
-
const cacheMutex = new Mutex();
|
|
28
|
+
const cacheMutex = new _asyncMutex.Mutex();
|
|
23
29
|
function getUniqueId(type, id) {
|
|
24
30
|
return `${type}.${id}`;
|
|
25
31
|
}
|
|
@@ -74,8 +80,8 @@ export function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
|
74
80
|
};
|
|
75
81
|
}
|
|
76
82
|
// Module-level specialized mutexes for pre-key operations
|
|
77
|
-
const preKeyMutex = new Mutex();
|
|
78
|
-
const signedPreKeyMutex = new Mutex();
|
|
83
|
+
const preKeyMutex = new _asyncMutex.Mutex();
|
|
84
|
+
const signedPreKeyMutex = new _asyncMutex.Mutex();
|
|
79
85
|
/**
|
|
80
86
|
* Get the appropriate mutex for the key type
|
|
81
87
|
*/
|
|
@@ -207,7 +213,7 @@ async function withMutexes(keyTypes, getKeyTypeMutex, fn) {
|
|
|
207
213
|
* @param logger logger to log events
|
|
208
214
|
* @returns SignalKeyStore with transaction capability
|
|
209
215
|
*/
|
|
210
|
-
|
|
216
|
+
const addTransactionCapability = (state, logger, {
|
|
211
217
|
maxCommitRetries,
|
|
212
218
|
delayBetweenTriesMs
|
|
213
219
|
}) => {
|
|
@@ -217,7 +223,7 @@ export const addTransactionCapability = (state, logger, {
|
|
|
217
223
|
let transactionCache = {};
|
|
218
224
|
let mutations = {};
|
|
219
225
|
// LRU Cache to hold mutexes for different key types
|
|
220
|
-
const mutexCache = new LRUCache({
|
|
226
|
+
const mutexCache = new _lruCache.LRUCache({
|
|
221
227
|
ttl: 60 * 60 * 1000,
|
|
222
228
|
// 1 hour
|
|
223
229
|
ttlAutopurge: true,
|
|
@@ -237,7 +243,7 @@ export const addTransactionCapability = (state, logger, {
|
|
|
237
243
|
function getMutex(key) {
|
|
238
244
|
let mutex = mutexCache.get(key);
|
|
239
245
|
if (!mutex) {
|
|
240
|
-
mutex = new Mutex();
|
|
246
|
+
mutex = new _asyncMutex.Mutex();
|
|
241
247
|
mutexCache.set(key, mutex);
|
|
242
248
|
logger.info({
|
|
243
249
|
key
|
|
@@ -272,7 +278,7 @@ export const addTransactionCapability = (state, logger, {
|
|
|
272
278
|
} catch (error) {
|
|
273
279
|
logger.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`);
|
|
274
280
|
if (tries > 0) {
|
|
275
|
-
await delay(delayBetweenTriesMs);
|
|
281
|
+
await (0, _generics.delay)(delayBetweenTriesMs);
|
|
276
282
|
}
|
|
277
283
|
}
|
|
278
284
|
}
|
|
@@ -456,15 +462,16 @@ export const addTransactionCapability = (state, logger, {
|
|
|
456
462
|
}
|
|
457
463
|
};
|
|
458
464
|
};
|
|
459
|
-
|
|
460
|
-
|
|
465
|
+
exports.addTransactionCapability = addTransactionCapability;
|
|
466
|
+
const initAuthCreds = () => {
|
|
467
|
+
const identityKey = _crypto2.Curve.generateKeyPair();
|
|
461
468
|
return {
|
|
462
|
-
noiseKey: Curve.generateKeyPair(),
|
|
463
|
-
pairingEphemeralKeyPair: Curve.generateKeyPair(),
|
|
469
|
+
noiseKey: _crypto2.Curve.generateKeyPair(),
|
|
470
|
+
pairingEphemeralKeyPair: _crypto2.Curve.generateKeyPair(),
|
|
464
471
|
signedIdentityKey: identityKey,
|
|
465
|
-
signedPreKey: signedKeyPair(identityKey, 1),
|
|
466
|
-
registrationId: generateRegistrationId(),
|
|
467
|
-
advSecretKey: randomBytes(32).toString('base64'),
|
|
472
|
+
signedPreKey: (0, _crypto2.signedKeyPair)(identityKey, 1),
|
|
473
|
+
registrationId: (0, _generics.generateRegistrationId)(),
|
|
474
|
+
advSecretKey: (0, _crypto.randomBytes)(32).toString('base64'),
|
|
468
475
|
processedHistoryMessages: [],
|
|
469
476
|
nextPreKeyId: 1,
|
|
470
477
|
firstUnuploadedPreKeyId: 1,
|
|
@@ -478,4 +485,4 @@ export const initAuthCreds = () => {
|
|
|
478
485
|
routingInfo: undefined
|
|
479
486
|
};
|
|
480
487
|
};
|
|
481
|
-
|
|
488
|
+
exports.initAuthCreds = initAuthCreds;
|
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
Object.defineProperty(exports, "__esModule", {
|
|
2
|
+
value: true
|
|
3
|
+
});
|
|
4
|
+
exports.readAndEmitEventStream = exports.captureEventStream = void 0;
|
|
5
|
+
var _events = _interopRequireDefault(require("events"));
|
|
6
|
+
var _fs = require("fs");
|
|
7
|
+
var _promises = require("fs/promises");
|
|
8
|
+
var _readline = require("readline");
|
|
9
|
+
var _generics = require("./generics.js");
|
|
10
|
+
var _makeMutex = require("./make-mutex.js");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
12
|
/**
|
|
8
13
|
* Captures events from a baileys event emitter & stores them in a file
|
|
9
14
|
* @param ev The event emitter to read events from
|
|
10
15
|
* @param filename File to save to
|
|
11
16
|
*/
|
|
12
|
-
|
|
17
|
+
const captureEventStream = (ev, filename) => {
|
|
13
18
|
const oldEmit = ev.emit;
|
|
14
19
|
// write mutex so data is appended in order
|
|
15
|
-
const writeMutex = makeMutex();
|
|
20
|
+
const writeMutex = (0, _makeMutex.makeMutex)();
|
|
16
21
|
// monkey patch eventemitter to capture all events
|
|
17
22
|
ev.emit = function (...args) {
|
|
18
23
|
const content = JSON.stringify({
|
|
@@ -22,7 +27,7 @@ export const captureEventStream = (ev, filename) => {
|
|
|
22
27
|
}) + '\n';
|
|
23
28
|
const result = oldEmit.apply(ev, args);
|
|
24
29
|
writeMutex.mutex(async () => {
|
|
25
|
-
await writeFile(filename, content, {
|
|
30
|
+
await (0, _promises.writeFile)(filename, content, {
|
|
26
31
|
flag: 'a'
|
|
27
32
|
});
|
|
28
33
|
});
|
|
@@ -34,12 +39,13 @@ export const captureEventStream = (ev, filename) => {
|
|
|
34
39
|
* @param filename filename containing event data
|
|
35
40
|
* @param delayIntervalMs delay between each event emit
|
|
36
41
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
42
|
+
exports.captureEventStream = captureEventStream;
|
|
43
|
+
const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
|
|
44
|
+
const ev = new _events.default();
|
|
39
45
|
const fireEvents = async () => {
|
|
40
46
|
// from: https://stackoverflow.com/questions/6156501/read-a-file-one-line-at-a-time-in-node-js
|
|
41
|
-
const fileStream = createReadStream(filename);
|
|
42
|
-
const rl = createInterface({
|
|
47
|
+
const fileStream = (0, _fs.createReadStream)(filename);
|
|
48
|
+
const rl = (0, _readline.createInterface)({
|
|
43
49
|
input: fileStream,
|
|
44
50
|
crlfDelay: Infinity
|
|
45
51
|
});
|
|
@@ -52,7 +58,7 @@ export const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
|
|
|
52
58
|
data
|
|
53
59
|
} = JSON.parse(line);
|
|
54
60
|
ev.emit(event, data);
|
|
55
|
-
delayIntervalMs && (await delay(delayIntervalMs));
|
|
61
|
+
delayIntervalMs && (await (0, _generics.delay)(delayIntervalMs));
|
|
56
62
|
}
|
|
57
63
|
}
|
|
58
64
|
fileStream.close();
|
|
@@ -62,4 +68,4 @@ export const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
|
|
|
62
68
|
task: fireEvents()
|
|
63
69
|
};
|
|
64
70
|
};
|
|
65
|
-
|
|
71
|
+
exports.readAndEmitEventStream = readAndEmitEventStream;
|
package/lib/Utils/business.js
CHANGED
|
@@ -1,26 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
Object.defineProperty(exports, "__esModule", {
|
|
2
|
+
value: true
|
|
3
|
+
});
|
|
4
|
+
exports.uploadingNecessaryImages = exports.toProductNode = exports.parseProductNode = exports.parseOrderDetailsNode = exports.parseCollectionsNode = exports.parseCatalogNode = void 0;
|
|
5
|
+
exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
|
|
6
|
+
var _boom = require("@hapi/boom");
|
|
7
|
+
var _crypto = require("crypto");
|
|
8
|
+
var _fs = require("fs");
|
|
9
|
+
var _os = require("os");
|
|
10
|
+
var _path = require("path");
|
|
11
|
+
var _index = require("../WABinary/index.js");
|
|
12
|
+
var _generics = require("./generics.js");
|
|
13
|
+
var _messagesMedia = require("./messages-media.js");
|
|
14
|
+
const parseCatalogNode = node => {
|
|
15
|
+
const catalogNode = (0, _index.getBinaryNodeChild)(node, 'product_catalog');
|
|
16
|
+
const products = (0, _index.getBinaryNodeChildren)(catalogNode, 'product').map(parseProductNode);
|
|
17
|
+
const paging = (0, _index.getBinaryNodeChild)(catalogNode, 'paging');
|
|
13
18
|
return {
|
|
14
19
|
products,
|
|
15
|
-
nextPageCursor: paging ? getBinaryNodeChildString(paging, 'after') : undefined
|
|
20
|
+
nextPageCursor: paging ? (0, _index.getBinaryNodeChildString)(paging, 'after') : undefined
|
|
16
21
|
};
|
|
17
22
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const
|
|
23
|
+
exports.parseCatalogNode = parseCatalogNode;
|
|
24
|
+
const parseCollectionsNode = node => {
|
|
25
|
+
const collectionsNode = (0, _index.getBinaryNodeChild)(node, 'collections');
|
|
26
|
+
const collections = (0, _index.getBinaryNodeChildren)(collectionsNode, 'collection').map(collectionNode => {
|
|
27
|
+
const id = (0, _index.getBinaryNodeChildString)(collectionNode, 'id');
|
|
28
|
+
const name = (0, _index.getBinaryNodeChildString)(collectionNode, 'name');
|
|
29
|
+
const products = (0, _index.getBinaryNodeChildren)(collectionNode, 'product').map(parseProductNode);
|
|
24
30
|
return {
|
|
25
31
|
id,
|
|
26
32
|
name,
|
|
@@ -32,30 +38,32 @@ export const parseCollectionsNode = node => {
|
|
|
32
38
|
collections
|
|
33
39
|
};
|
|
34
40
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
41
|
+
exports.parseCollectionsNode = parseCollectionsNode;
|
|
42
|
+
const parseOrderDetailsNode = node => {
|
|
43
|
+
const orderNode = (0, _index.getBinaryNodeChild)(node, 'order');
|
|
44
|
+
const products = (0, _index.getBinaryNodeChildren)(orderNode, 'product').map(productNode => {
|
|
45
|
+
const imageNode = (0, _index.getBinaryNodeChild)(productNode, 'image');
|
|
39
46
|
return {
|
|
40
|
-
id: getBinaryNodeChildString(productNode, 'id'),
|
|
41
|
-
name: getBinaryNodeChildString(productNode, 'name'),
|
|
42
|
-
imageUrl: getBinaryNodeChildString(imageNode, 'url'),
|
|
43
|
-
price: +getBinaryNodeChildString(productNode, 'price'),
|
|
44
|
-
currency: getBinaryNodeChildString(productNode, 'currency'),
|
|
45
|
-
quantity: +getBinaryNodeChildString(productNode, 'quantity')
|
|
47
|
+
id: (0, _index.getBinaryNodeChildString)(productNode, 'id'),
|
|
48
|
+
name: (0, _index.getBinaryNodeChildString)(productNode, 'name'),
|
|
49
|
+
imageUrl: (0, _index.getBinaryNodeChildString)(imageNode, 'url'),
|
|
50
|
+
price: +(0, _index.getBinaryNodeChildString)(productNode, 'price'),
|
|
51
|
+
currency: (0, _index.getBinaryNodeChildString)(productNode, 'currency'),
|
|
52
|
+
quantity: +(0, _index.getBinaryNodeChildString)(productNode, 'quantity')
|
|
46
53
|
};
|
|
47
54
|
});
|
|
48
|
-
const priceNode = getBinaryNodeChild(orderNode, 'price');
|
|
55
|
+
const priceNode = (0, _index.getBinaryNodeChild)(orderNode, 'price');
|
|
49
56
|
const orderDetails = {
|
|
50
57
|
price: {
|
|
51
|
-
total: +getBinaryNodeChildString(priceNode, 'total'),
|
|
52
|
-
currency: getBinaryNodeChildString(priceNode, 'currency')
|
|
58
|
+
total: +(0, _index.getBinaryNodeChildString)(priceNode, 'total'),
|
|
59
|
+
currency: (0, _index.getBinaryNodeChildString)(priceNode, 'currency')
|
|
53
60
|
},
|
|
54
61
|
products
|
|
55
62
|
};
|
|
56
63
|
return orderDetails;
|
|
57
64
|
};
|
|
58
|
-
|
|
65
|
+
exports.parseOrderDetailsNode = parseOrderDetailsNode;
|
|
66
|
+
const toProductNode = (productId, product) => {
|
|
59
67
|
const attrs = {};
|
|
60
68
|
const content = [];
|
|
61
69
|
if (typeof productId !== 'undefined') {
|
|
@@ -92,7 +100,7 @@ export const toProductNode = (productId, product) => {
|
|
|
92
100
|
attrs: {},
|
|
93
101
|
content: product.images.map(img => {
|
|
94
102
|
if (!('url' in img)) {
|
|
95
|
-
throw new Boom('Expected img for product to already be uploaded', {
|
|
103
|
+
throw new _boom.Boom('Expected img for product to already be uploaded', {
|
|
96
104
|
statusCode: 400
|
|
97
105
|
});
|
|
98
106
|
}
|
|
@@ -147,24 +155,25 @@ export const toProductNode = (productId, product) => {
|
|
|
147
155
|
};
|
|
148
156
|
return node;
|
|
149
157
|
};
|
|
150
|
-
|
|
158
|
+
exports.toProductNode = toProductNode;
|
|
159
|
+
const parseProductNode = productNode => {
|
|
151
160
|
const isHidden = productNode.attrs.is_hidden === 'true';
|
|
152
|
-
const id = getBinaryNodeChildString(productNode, 'id');
|
|
153
|
-
const mediaNode = getBinaryNodeChild(productNode, 'media');
|
|
154
|
-
const statusInfoNode = getBinaryNodeChild(productNode, 'status_info');
|
|
161
|
+
const id = (0, _index.getBinaryNodeChildString)(productNode, 'id');
|
|
162
|
+
const mediaNode = (0, _index.getBinaryNodeChild)(productNode, 'media');
|
|
163
|
+
const statusInfoNode = (0, _index.getBinaryNodeChild)(productNode, 'status_info');
|
|
155
164
|
const product = {
|
|
156
165
|
id,
|
|
157
166
|
imageUrls: parseImageUrls(mediaNode),
|
|
158
167
|
reviewStatus: {
|
|
159
|
-
whatsapp: getBinaryNodeChildString(statusInfoNode, 'status')
|
|
168
|
+
whatsapp: (0, _index.getBinaryNodeChildString)(statusInfoNode, 'status')
|
|
160
169
|
},
|
|
161
170
|
availability: 'in stock',
|
|
162
|
-
name: getBinaryNodeChildString(productNode, 'name'),
|
|
163
|
-
retailerId: getBinaryNodeChildString(productNode, 'retailer_id'),
|
|
164
|
-
url: getBinaryNodeChildString(productNode, 'url'),
|
|
165
|
-
description: getBinaryNodeChildString(productNode, 'description'),
|
|
166
|
-
price: +getBinaryNodeChildString(productNode, 'price'),
|
|
167
|
-
currency: getBinaryNodeChildString(productNode, 'currency'),
|
|
171
|
+
name: (0, _index.getBinaryNodeChildString)(productNode, 'name'),
|
|
172
|
+
retailerId: (0, _index.getBinaryNodeChildString)(productNode, 'retailer_id'),
|
|
173
|
+
url: (0, _index.getBinaryNodeChildString)(productNode, 'url'),
|
|
174
|
+
description: (0, _index.getBinaryNodeChildString)(productNode, 'description'),
|
|
175
|
+
price: +(0, _index.getBinaryNodeChildString)(productNode, 'price'),
|
|
176
|
+
currency: (0, _index.getBinaryNodeChildString)(productNode, 'currency'),
|
|
168
177
|
isHidden
|
|
169
178
|
};
|
|
170
179
|
return product;
|
|
@@ -172,7 +181,8 @@ export const parseProductNode = productNode => {
|
|
|
172
181
|
/**
|
|
173
182
|
* Uploads images not already uploaded to WA's servers
|
|
174
183
|
*/
|
|
175
|
-
|
|
184
|
+
exports.parseProductNode = parseProductNode;
|
|
185
|
+
async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, timeoutMs = 30000) {
|
|
176
186
|
product = {
|
|
177
187
|
...product,
|
|
178
188
|
images: product.images ? await uploadingNecessaryImages(product.images, waUploadToServer, timeoutMs) : product.images
|
|
@@ -182,7 +192,7 @@ export async function uploadingNecessaryImagesOfProduct(product, waUploadToServe
|
|
|
182
192
|
/**
|
|
183
193
|
* Uploads images not already uploaded to WA's servers
|
|
184
194
|
*/
|
|
185
|
-
|
|
195
|
+
const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30000) => {
|
|
186
196
|
const results = await Promise.all(images.map(async img => {
|
|
187
197
|
if ('url' in img) {
|
|
188
198
|
const url = img.url.toString();
|
|
@@ -194,10 +204,10 @@ export const uploadingNecessaryImages = async (images, waUploadToServer, timeout
|
|
|
194
204
|
}
|
|
195
205
|
const {
|
|
196
206
|
stream
|
|
197
|
-
} = await getStream(img);
|
|
198
|
-
const hasher = createHash('sha256');
|
|
199
|
-
const filePath = join(tmpdir(), 'img' + generateMessageIDV2());
|
|
200
|
-
const encFileWriteStream = createWriteStream(filePath);
|
|
207
|
+
} = await (0, _messagesMedia.getStream)(img);
|
|
208
|
+
const hasher = (0, _crypto.createHash)('sha256');
|
|
209
|
+
const filePath = (0, _path.join)((0, _os.tmpdir)(), 'img' + (0, _generics.generateMessageIDV2)());
|
|
210
|
+
const encFileWriteStream = (0, _fs.createWriteStream)(filePath);
|
|
201
211
|
for await (const block of stream) {
|
|
202
212
|
hasher.update(block);
|
|
203
213
|
encFileWriteStream.write(block);
|
|
@@ -210,25 +220,25 @@ export const uploadingNecessaryImages = async (images, waUploadToServer, timeout
|
|
|
210
220
|
fileEncSha256B64: sha,
|
|
211
221
|
timeoutMs
|
|
212
222
|
});
|
|
213
|
-
await
|
|
223
|
+
await _fs.promises.unlink(filePath).catch(err => console.log('Error deleting temp file ', err));
|
|
214
224
|
return {
|
|
215
|
-
url: getUrlFromDirectPath(directPath)
|
|
225
|
+
url: (0, _messagesMedia.getUrlFromDirectPath)(directPath)
|
|
216
226
|
};
|
|
217
227
|
}));
|
|
218
228
|
return results;
|
|
219
229
|
};
|
|
230
|
+
exports.uploadingNecessaryImages = uploadingNecessaryImages;
|
|
220
231
|
const parseImageUrls = mediaNode => {
|
|
221
|
-
const imgNode = getBinaryNodeChild(mediaNode, 'image');
|
|
232
|
+
const imgNode = (0, _index.getBinaryNodeChild)(mediaNode, 'image');
|
|
222
233
|
return {
|
|
223
|
-
requested: getBinaryNodeChildString(imgNode, 'request_image_url'),
|
|
224
|
-
original: getBinaryNodeChildString(imgNode, 'original_image_url')
|
|
234
|
+
requested: (0, _index.getBinaryNodeChildString)(imgNode, 'request_image_url'),
|
|
235
|
+
original: (0, _index.getBinaryNodeChildString)(imgNode, 'original_image_url')
|
|
225
236
|
};
|
|
226
237
|
};
|
|
227
238
|
const parseStatusInfo = mediaNode => {
|
|
228
|
-
const node = getBinaryNodeChild(mediaNode, 'status_info');
|
|
239
|
+
const node = (0, _index.getBinaryNodeChild)(mediaNode, 'status_info');
|
|
229
240
|
return {
|
|
230
|
-
status: getBinaryNodeChildString(node, 'status'),
|
|
231
|
-
canAppeal: getBinaryNodeChildString(node, 'can_appeal') === 'true'
|
|
241
|
+
status: (0, _index.getBinaryNodeChildString)(node, 'status'),
|
|
242
|
+
canAppeal: (0, _index.getBinaryNodeChildString)(node, 'can_appeal') === 'true'
|
|
232
243
|
};
|
|
233
|
-
};
|
|
234
|
-
//# sourceMappingURL=business.js.map
|
|
244
|
+
};
|