@ubedsockets/baileys 1.6.6 → 1.6.8
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/GenerateStatics.sh +4 -3
- package/WAProto/WAProto.proto +511 -1215
- package/WAProto/index.js +131318 -59331
- package/lib/Defaults/index.js +92 -76
- package/lib/Signal/Group/ciphertext-message.js +5 -2
- package/lib/Signal/Group/group-session-builder.js +41 -7
- package/lib/Signal/Group/group_cipher.js +51 -37
- package/lib/Signal/Group/index.js +57 -12
- package/lib/Signal/Group/keyhelper.js +44 -7
- package/lib/Signal/Group/sender-chain-key.js +15 -7
- package/lib/Signal/Group/sender-key-distribution-message.js +11 -8
- package/lib/Signal/Group/sender-key-message.js +12 -9
- package/lib/Signal/Group/sender-key-name.js +5 -2
- package/lib/Signal/Group/sender-key-record.js +21 -9
- package/lib/Signal/Group/sender-key-state.js +42 -27
- package/lib/Signal/Group/sender-message-key.js +7 -4
- package/lib/Signal/libsignal.js +90 -347
- package/lib/Socket/Client/index.js +18 -3
- package/lib/Socket/Client/types.js +6 -4
- package/lib/Socket/Client/websocket.js +78 -21
- package/lib/Socket/business.js +43 -162
- package/lib/Socket/chats.js +249 -571
- package/lib/Socket/groups.js +99 -114
- package/lib/Socket/index.js +9 -11
- package/lib/Socket/messages-recv.js +559 -1277
- package/lib/Socket/messages-send.js +669 -674
- package/lib/Socket/newsletter.js +286 -149
- package/lib/Socket/socket.js +235 -548
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +4 -8
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +5 -3
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.js +7 -11
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +2 -56
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.js +136 -239
- package/lib/Utils/business.js +69 -66
- package/lib/Utils/chat-utils.js +238 -380
- package/lib/Utils/crypto.js +127 -56
- package/lib/Utils/decode-wa-message.js +63 -173
- package/lib/Utils/event-buffer.js +70 -174
- package/lib/Utils/generics.js +207 -159
- package/lib/Utils/history.js +53 -93
- package/lib/Utils/index.js +33 -22
- package/lib/Utils/link-preview.js +58 -17
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.js +46 -3
- package/lib/Utils/make-mutex.js +34 -24
- package/lib/Utils/messages-media.js +744 -483
- package/lib/Utils/messages.js +621 -411
- package/lib/Utils/noise-handler.js +99 -149
- package/lib/Utils/process-message.js +150 -459
- package/lib/Utils/signal.js +73 -112
- package/lib/Utils/use-multi-file-auth-state.js +27 -23
- package/lib/Utils/validate-connection.js +104 -74
- package/lib/WABinary/constants.js +11 -9
- package/lib/WABinary/decode.js +52 -49
- package/lib/WABinary/encode.js +49 -19
- package/lib/WABinary/generic-utils.js +43 -46
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.js +45 -72
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.js +11958 -19461
- package/lib/WAM/encode.js +22 -17
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +13 -33
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +11 -8
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +8 -13
- package/lib/WAUSync/Protocols/index.js +20 -6
- package/lib/WAUSync/USyncQuery.js +35 -44
- package/lib/WAUSync/USyncUser.js +5 -10
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.js +70 -11
- package/package.json +60 -100
- package/engine-requirements.js +0 -10
package/lib/Utils/business.js
CHANGED
|
@@ -1,26 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const catalogNode = getBinaryNodeChild(node, 'product_catalog');
|
|
11
|
-
const products = getBinaryNodeChildren(catalogNode, 'product').map(parseProductNode);
|
|
12
|
-
const paging = getBinaryNodeChild(catalogNode, 'paging');
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uploadingNecessaryImages = exports.parseProductNode = exports.toProductNode = exports.parseOrderDetailsNode = exports.parseCollectionsNode = exports.parseCatalogNode = void 0;
|
|
4
|
+
exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
|
|
5
|
+
const boom_1 = require("@hapi/boom");
|
|
6
|
+
const crypto_1 = require("crypto");
|
|
7
|
+
const WABinary_1 = require("../WABinary");
|
|
8
|
+
const messages_media_1 = require("./messages-media");
|
|
9
|
+
const parseCatalogNode = (node) => {
|
|
10
|
+
const catalogNode = (0, WABinary_1.getBinaryNodeChild)(node, 'product_catalog');
|
|
11
|
+
const products = (0, WABinary_1.getBinaryNodeChildren)(catalogNode, 'product').map(exports.parseProductNode);
|
|
12
|
+
const paging = (0, WABinary_1.getBinaryNodeChild)(catalogNode, 'paging');
|
|
13
13
|
return {
|
|
14
14
|
products,
|
|
15
|
-
nextPageCursor: paging
|
|
15
|
+
nextPageCursor: paging
|
|
16
|
+
? (0, WABinary_1.getBinaryNodeChildString)(paging, 'after')
|
|
17
|
+
: undefined
|
|
16
18
|
};
|
|
17
19
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const
|
|
20
|
+
exports.parseCatalogNode = parseCatalogNode;
|
|
21
|
+
const parseCollectionsNode = (node) => {
|
|
22
|
+
const collectionsNode = (0, WABinary_1.getBinaryNodeChild)(node, 'collections');
|
|
23
|
+
const collections = (0, WABinary_1.getBinaryNodeChildren)(collectionsNode, 'collection').map(collectionNode => {
|
|
24
|
+
const id = (0, WABinary_1.getBinaryNodeChildString)(collectionNode, 'id');
|
|
25
|
+
const name = (0, WABinary_1.getBinaryNodeChildString)(collectionNode, 'name');
|
|
26
|
+
const products = (0, WABinary_1.getBinaryNodeChildren)(collectionNode, 'product').map(exports.parseProductNode);
|
|
24
27
|
return {
|
|
25
28
|
id,
|
|
26
29
|
name,
|
|
@@ -32,30 +35,32 @@ export const parseCollectionsNode = (node) => {
|
|
|
32
35
|
collections
|
|
33
36
|
};
|
|
34
37
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
38
|
+
exports.parseCollectionsNode = parseCollectionsNode;
|
|
39
|
+
const parseOrderDetailsNode = (node) => {
|
|
40
|
+
const orderNode = (0, WABinary_1.getBinaryNodeChild)(node, 'order');
|
|
41
|
+
const products = (0, WABinary_1.getBinaryNodeChildren)(orderNode, 'product').map(productNode => {
|
|
42
|
+
const imageNode = (0, WABinary_1.getBinaryNodeChild)(productNode, 'image');
|
|
39
43
|
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')
|
|
44
|
+
id: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'id'),
|
|
45
|
+
name: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'name'),
|
|
46
|
+
imageUrl: (0, WABinary_1.getBinaryNodeChildString)(imageNode, 'url'),
|
|
47
|
+
price: +(0, WABinary_1.getBinaryNodeChildString)(productNode, 'price'),
|
|
48
|
+
currency: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'currency'),
|
|
49
|
+
quantity: +(0, WABinary_1.getBinaryNodeChildString)(productNode, 'quantity')
|
|
46
50
|
};
|
|
47
51
|
});
|
|
48
|
-
const priceNode = getBinaryNodeChild(orderNode, 'price');
|
|
52
|
+
const priceNode = (0, WABinary_1.getBinaryNodeChild)(orderNode, 'price');
|
|
49
53
|
const orderDetails = {
|
|
50
54
|
price: {
|
|
51
|
-
total: +getBinaryNodeChildString(priceNode, 'total'),
|
|
52
|
-
currency: getBinaryNodeChildString(priceNode, 'currency')
|
|
55
|
+
total: +(0, WABinary_1.getBinaryNodeChildString)(priceNode, 'total'),
|
|
56
|
+
currency: (0, WABinary_1.getBinaryNodeChildString)(priceNode, 'currency'),
|
|
53
57
|
},
|
|
54
58
|
products
|
|
55
59
|
};
|
|
56
60
|
return orderDetails;
|
|
57
61
|
};
|
|
58
|
-
|
|
62
|
+
exports.parseOrderDetailsNode = parseOrderDetailsNode;
|
|
63
|
+
const toProductNode = (productId, product) => {
|
|
59
64
|
const attrs = {};
|
|
60
65
|
const content = [];
|
|
61
66
|
if (typeof productId !== 'undefined') {
|
|
@@ -92,7 +97,7 @@ export const toProductNode = (productId, product) => {
|
|
|
92
97
|
attrs: {},
|
|
93
98
|
content: product.images.map(img => {
|
|
94
99
|
if (!('url' in img)) {
|
|
95
|
-
throw new Boom('Expected img for product to already be uploaded', { statusCode: 400 });
|
|
100
|
+
throw new boom_1.Boom('Expected img for product to already be uploaded', { statusCode: 400 });
|
|
96
101
|
}
|
|
97
102
|
return {
|
|
98
103
|
tag: 'image',
|
|
@@ -150,44 +155,44 @@ export const toProductNode = (productId, product) => {
|
|
|
150
155
|
};
|
|
151
156
|
return node;
|
|
152
157
|
};
|
|
153
|
-
|
|
158
|
+
exports.toProductNode = toProductNode;
|
|
159
|
+
const parseProductNode = (productNode) => {
|
|
154
160
|
const isHidden = productNode.attrs.is_hidden === 'true';
|
|
155
|
-
const id = getBinaryNodeChildString(productNode, 'id');
|
|
156
|
-
const mediaNode = getBinaryNodeChild(productNode, 'media');
|
|
157
|
-
const statusInfoNode = getBinaryNodeChild(productNode, 'status_info');
|
|
161
|
+
const id = (0, WABinary_1.getBinaryNodeChildString)(productNode, 'id');
|
|
162
|
+
const mediaNode = (0, WABinary_1.getBinaryNodeChild)(productNode, 'media');
|
|
163
|
+
const statusInfoNode = (0, WABinary_1.getBinaryNodeChild)(productNode, 'status_info');
|
|
158
164
|
const product = {
|
|
159
165
|
id,
|
|
160
166
|
imageUrls: parseImageUrls(mediaNode),
|
|
161
167
|
reviewStatus: {
|
|
162
|
-
whatsapp: getBinaryNodeChildString(statusInfoNode, 'status')
|
|
168
|
+
whatsapp: (0, WABinary_1.getBinaryNodeChildString)(statusInfoNode, 'status'),
|
|
163
169
|
},
|
|
164
170
|
availability: 'in stock',
|
|
165
|
-
name: getBinaryNodeChildString(productNode, 'name'),
|
|
166
|
-
retailerId: getBinaryNodeChildString(productNode, 'retailer_id'),
|
|
167
|
-
url: getBinaryNodeChildString(productNode, 'url'),
|
|
168
|
-
description: getBinaryNodeChildString(productNode, 'description'),
|
|
169
|
-
price: +getBinaryNodeChildString(productNode, 'price'),
|
|
170
|
-
currency: getBinaryNodeChildString(productNode, 'currency'),
|
|
171
|
-
isHidden
|
|
171
|
+
name: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'name'),
|
|
172
|
+
retailerId: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'retailer_id'),
|
|
173
|
+
url: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'url'),
|
|
174
|
+
description: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'description'),
|
|
175
|
+
price: +(0, WABinary_1.getBinaryNodeChildString)(productNode, 'price'),
|
|
176
|
+
currency: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'currency'),
|
|
177
|
+
isHidden,
|
|
172
178
|
};
|
|
173
179
|
return product;
|
|
174
180
|
};
|
|
181
|
+
exports.parseProductNode = parseProductNode;
|
|
175
182
|
/**
|
|
176
183
|
* Uploads images not already uploaded to WA's servers
|
|
177
184
|
*/
|
|
178
|
-
|
|
185
|
+
async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, timeoutMs = 30000) {
|
|
179
186
|
product = {
|
|
180
187
|
...product,
|
|
181
|
-
images: product.images
|
|
182
|
-
? await uploadingNecessaryImages(product.images, waUploadToServer, timeoutMs)
|
|
183
|
-
: product.images
|
|
188
|
+
images: product.images ? await (0, exports.uploadingNecessaryImages)(product.images, waUploadToServer, timeoutMs) : product.images
|
|
184
189
|
};
|
|
185
190
|
return product;
|
|
186
191
|
}
|
|
187
192
|
/**
|
|
188
193
|
* Uploads images not already uploaded to WA's servers
|
|
189
194
|
*/
|
|
190
|
-
|
|
195
|
+
const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30000) => {
|
|
191
196
|
const results = await Promise.all(images.map(async (img) => {
|
|
192
197
|
if ('url' in img) {
|
|
193
198
|
const url = img.url.toString();
|
|
@@ -195,37 +200,35 @@ export const uploadingNecessaryImages = async (images, waUploadToServer, timeout
|
|
|
195
200
|
return { url };
|
|
196
201
|
}
|
|
197
202
|
}
|
|
198
|
-
const { stream } = await getStream(img);
|
|
199
|
-
const hasher = createHash('sha256');
|
|
200
|
-
const
|
|
201
|
-
const encFileWriteStream = createWriteStream(filePath);
|
|
203
|
+
const { stream } = await (0, messages_media_1.getStream)(img);
|
|
204
|
+
const hasher = (0, crypto_1.createHash)('sha256');
|
|
205
|
+
const contentBlocks = [];
|
|
202
206
|
for await (const block of stream) {
|
|
203
207
|
hasher.update(block);
|
|
204
|
-
|
|
208
|
+
contentBlocks.push(block);
|
|
205
209
|
}
|
|
206
210
|
const sha = hasher.digest('base64');
|
|
207
|
-
const { directPath } = await waUploadToServer(
|
|
211
|
+
const { directPath } = await waUploadToServer((0, messages_media_1.toReadable)(Buffer.concat(contentBlocks)), {
|
|
208
212
|
mediaType: 'product-catalog-image',
|
|
209
213
|
fileEncSha256B64: sha,
|
|
210
214
|
timeoutMs
|
|
211
215
|
});
|
|
212
|
-
|
|
213
|
-
return { url: getUrlFromDirectPath(directPath) };
|
|
216
|
+
return { url: (0, messages_media_1.getUrlFromDirectPath)(directPath) };
|
|
214
217
|
}));
|
|
215
218
|
return results;
|
|
216
219
|
};
|
|
220
|
+
exports.uploadingNecessaryImages = uploadingNecessaryImages;
|
|
217
221
|
const parseImageUrls = (mediaNode) => {
|
|
218
|
-
const imgNode = getBinaryNodeChild(mediaNode, 'image');
|
|
222
|
+
const imgNode = (0, WABinary_1.getBinaryNodeChild)(mediaNode, 'image');
|
|
219
223
|
return {
|
|
220
|
-
requested: getBinaryNodeChildString(imgNode, 'request_image_url'),
|
|
221
|
-
original: getBinaryNodeChildString(imgNode, 'original_image_url')
|
|
224
|
+
requested: (0, WABinary_1.getBinaryNodeChildString)(imgNode, 'request_image_url'),
|
|
225
|
+
original: (0, WABinary_1.getBinaryNodeChildString)(imgNode, 'original_image_url')
|
|
222
226
|
};
|
|
223
227
|
};
|
|
224
228
|
const parseStatusInfo = (mediaNode) => {
|
|
225
|
-
const node = getBinaryNodeChild(mediaNode, 'status_info');
|
|
229
|
+
const node = (0, WABinary_1.getBinaryNodeChild)(mediaNode, 'status_info');
|
|
226
230
|
return {
|
|
227
|
-
status: getBinaryNodeChildString(node, 'status'),
|
|
228
|
-
canAppeal: getBinaryNodeChildString(node, 'can_appeal') === 'true'
|
|
231
|
+
status: (0, WABinary_1.getBinaryNodeChildString)(node, 'status'),
|
|
232
|
+
canAppeal: (0, WABinary_1.getBinaryNodeChildString)(node, 'can_appeal') === 'true',
|
|
229
233
|
};
|
|
230
234
|
};
|
|
231
|
-
//# sourceMappingURL=business.js.map
|