violetics 7.0.0-alpha → 7.0.2-alpha
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 +3 -2
- package/README.md +1001 -232
- package/WAProto/index.js +75379 -142631
- package/engine-requirements.js +11 -8
- package/lib/Defaults/index.js +132 -144
- package/lib/Signal/Group/ciphertext-message.js +2 -6
- package/lib/Signal/Group/group-session-builder.js +7 -42
- package/lib/Signal/Group/group_cipher.js +37 -52
- package/lib/Signal/Group/index.js +11 -57
- package/lib/Signal/Group/keyhelper.js +7 -45
- package/lib/Signal/Group/sender-chain-key.js +7 -16
- package/lib/Signal/Group/sender-key-distribution-message.js +8 -12
- package/lib/Signal/Group/sender-key-message.js +9 -13
- package/lib/Signal/Group/sender-key-name.js +2 -6
- package/lib/Signal/Group/sender-key-record.js +9 -22
- package/lib/Signal/Group/sender-key-state.js +27 -43
- package/lib/Signal/Group/sender-message-key.js +4 -8
- package/lib/Signal/libsignal.js +319 -94
- package/lib/Signal/lid-mapping.js +224 -139
- package/lib/Socket/Client/index.js +2 -19
- package/lib/Socket/Client/types.js +10 -0
- package/lib/Socket/Client/websocket.js +53 -0
- package/lib/Socket/business.js +162 -44
- package/lib/Socket/chats.js +477 -442
- package/lib/Socket/communities.js +430 -0
- package/lib/Socket/groups.js +110 -99
- package/lib/Socket/index.js +10 -10
- package/lib/Socket/messages-recv.js +878 -552
- package/lib/Socket/messages-send.js +859 -428
- package/lib/Socket/mex.js +41 -0
- package/lib/Socket/newsletter.js +195 -390
- package/lib/Socket/socket.js +463 -289
- package/lib/Store/index.js +3 -10
- package/lib/Store/make-in-memory-store.js +73 -79
- package/lib/Store/make-ordered-dictionary.js +4 -7
- package/lib/Store/object-repository.js +2 -6
- package/lib/Types/Auth.js +1 -2
- package/lib/Types/Bussines.js +1 -0
- package/lib/Types/Call.js +1 -2
- package/lib/Types/Chat.js +7 -4
- package/lib/Types/Contact.js +1 -2
- package/lib/Types/Events.js +1 -2
- package/lib/Types/GroupMetadata.js +1 -2
- package/lib/Types/Label.js +2 -5
- package/lib/Types/LabelAssociation.js +2 -5
- package/lib/Types/Message.js +17 -9
- package/lib/Types/Newsletter.js +33 -38
- package/lib/Types/Product.js +1 -2
- package/lib/Types/Signal.js +1 -2
- package/lib/Types/Socket.js +2 -2
- package/lib/Types/State.js +12 -2
- package/lib/Types/USync.js +1 -2
- package/lib/Types/index.js +14 -31
- package/lib/Utils/auth-utils.js +228 -145
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/business.js +66 -70
- package/lib/Utils/chat-utils.js +331 -249
- package/lib/Utils/crypto.js +57 -91
- package/lib/Utils/decode-wa-message.js +168 -84
- package/lib/Utils/event-buffer.js +138 -80
- package/lib/Utils/generics.js +180 -297
- package/lib/Utils/history.js +83 -49
- package/lib/Utils/identity-change-handler.js +48 -0
- package/lib/Utils/index.js +19 -33
- package/lib/Utils/link-preview.js +14 -23
- package/lib/Utils/logger.js +2 -7
- package/lib/Utils/lt-hash.js +2 -46
- package/lib/Utils/make-mutex.js +24 -35
- package/lib/Utils/message-retry-manager.js +224 -0
- package/lib/Utils/messages-media.js +501 -496
- package/lib/Utils/messages.js +1428 -362
- package/lib/Utils/noise-handler.js +145 -100
- package/lib/Utils/pre-key-manager.js +105 -0
- package/lib/Utils/process-message.js +356 -150
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/signal.js +78 -73
- package/lib/Utils/sync-action-utils.js +47 -0
- package/lib/Utils/tc-token-utils.js +17 -0
- package/lib/Utils/use-multi-file-auth-state.js +32 -34
- package/lib/Utils/validate-connection.js +91 -107
- package/lib/WABinary/constants.js +1300 -1304
- package/lib/WABinary/decode.js +26 -48
- package/lib/WABinary/encode.js +109 -155
- package/lib/WABinary/generic-utils.js +161 -149
- package/lib/WABinary/index.js +5 -21
- package/lib/WABinary/jid-utils.js +73 -40
- package/lib/WABinary/types.js +1 -2
- package/lib/WAM/BinaryInfo.js +2 -6
- package/lib/WAM/constants.js +19070 -11568
- package/lib/WAM/encode.js +17 -23
- package/lib/WAM/index.js +3 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +8 -12
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -15
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -13
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -14
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -23
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +13 -9
- package/lib/WAUSync/Protocols/index.js +4 -20
- package/lib/WAUSync/USyncQuery.js +40 -36
- package/lib/WAUSync/USyncUser.js +2 -6
- package/lib/WAUSync/index.js +3 -19
- package/lib/index.js +11 -44
- package/package.json +75 -108
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.js +0 -111
- package/lib/Socket/groupStatus.js +0 -637
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/usync.js +0 -70
- package/lib/Store/make-cache-manager-store.js +0 -83
- package/lib/Utils/baileys-event-stream.js +0 -63
package/lib/Utils/business.js
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { createHash } from 'crypto';
|
|
3
|
+
import { createWriteStream, promises as fs } from 'fs';
|
|
4
|
+
import { tmpdir } from 'os';
|
|
5
|
+
import { join } from 'path';
|
|
6
|
+
import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString } from '../WABinary/index.js';
|
|
7
|
+
import { generateMessageIDV2 } from './generics.js';
|
|
8
|
+
import { getStream, getUrlFromDirectPath } from './messages-media.js';
|
|
9
|
+
export const parseCatalogNode = (node) => {
|
|
10
|
+
const catalogNode = getBinaryNodeChild(node, 'product_catalog');
|
|
11
|
+
const products = getBinaryNodeChildren(catalogNode, 'product').map(parseProductNode);
|
|
12
|
+
const paging = getBinaryNodeChild(catalogNode, 'paging');
|
|
12
13
|
return {
|
|
13
14
|
products,
|
|
14
|
-
nextPageCursor: paging
|
|
15
|
-
? (0, WABinary_1.getBinaryNodeChildString)(paging, 'after')
|
|
16
|
-
: undefined
|
|
15
|
+
nextPageCursor: paging ? getBinaryNodeChildString(paging, 'after') : undefined
|
|
17
16
|
};
|
|
18
17
|
};
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const products = (0, WABinary_1.getBinaryNodeChildren)(collectionNode, 'product').map(exports.parseProductNode);
|
|
18
|
+
export const parseCollectionsNode = (node) => {
|
|
19
|
+
const collectionsNode = getBinaryNodeChild(node, 'collections');
|
|
20
|
+
const collections = getBinaryNodeChildren(collectionsNode, 'collection').map(collectionNode => {
|
|
21
|
+
const id = getBinaryNodeChildString(collectionNode, 'id');
|
|
22
|
+
const name = getBinaryNodeChildString(collectionNode, 'name');
|
|
23
|
+
const products = getBinaryNodeChildren(collectionNode, 'product').map(parseProductNode);
|
|
26
24
|
return {
|
|
27
25
|
id,
|
|
28
26
|
name,
|
|
@@ -34,32 +32,30 @@ const parseCollectionsNode = (node) => {
|
|
|
34
32
|
collections
|
|
35
33
|
};
|
|
36
34
|
};
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
const imageNode = (0, WABinary_1.getBinaryNodeChild)(productNode, 'image');
|
|
35
|
+
export const parseOrderDetailsNode = (node) => {
|
|
36
|
+
const orderNode = getBinaryNodeChild(node, 'order');
|
|
37
|
+
const products = getBinaryNodeChildren(orderNode, 'product').map(productNode => {
|
|
38
|
+
const imageNode = getBinaryNodeChild(productNode, 'image');
|
|
42
39
|
return {
|
|
43
|
-
id:
|
|
44
|
-
name:
|
|
45
|
-
imageUrl:
|
|
46
|
-
price: +
|
|
47
|
-
currency:
|
|
48
|
-
quantity: +
|
|
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')
|
|
49
46
|
};
|
|
50
47
|
});
|
|
51
|
-
const priceNode =
|
|
48
|
+
const priceNode = getBinaryNodeChild(orderNode, 'price');
|
|
52
49
|
const orderDetails = {
|
|
53
50
|
price: {
|
|
54
|
-
total: +
|
|
55
|
-
currency:
|
|
51
|
+
total: +getBinaryNodeChildString(priceNode, 'total'),
|
|
52
|
+
currency: getBinaryNodeChildString(priceNode, 'currency')
|
|
56
53
|
},
|
|
57
54
|
products
|
|
58
55
|
};
|
|
59
56
|
return orderDetails;
|
|
60
57
|
};
|
|
61
|
-
|
|
62
|
-
const toProductNode = (productId, product) => {
|
|
58
|
+
export const toProductNode = (productId, product) => {
|
|
63
59
|
const attrs = {};
|
|
64
60
|
const content = [];
|
|
65
61
|
if (typeof productId !== 'undefined') {
|
|
@@ -96,7 +92,7 @@ const toProductNode = (productId, product) => {
|
|
|
96
92
|
attrs: {},
|
|
97
93
|
content: product.images.map(img => {
|
|
98
94
|
if (!('url' in img)) {
|
|
99
|
-
throw new
|
|
95
|
+
throw new Boom('Expected img for product to already be uploaded', { statusCode: 400 });
|
|
100
96
|
}
|
|
101
97
|
return {
|
|
102
98
|
tag: 'image',
|
|
@@ -154,45 +150,44 @@ const toProductNode = (productId, product) => {
|
|
|
154
150
|
};
|
|
155
151
|
return node;
|
|
156
152
|
};
|
|
157
|
-
|
|
158
|
-
const parseProductNode = (productNode) => {
|
|
153
|
+
export const parseProductNode = (productNode) => {
|
|
159
154
|
const isHidden = productNode.attrs.is_hidden === 'true';
|
|
160
|
-
const id =
|
|
161
|
-
const mediaNode =
|
|
162
|
-
const statusInfoNode =
|
|
155
|
+
const id = getBinaryNodeChildString(productNode, 'id');
|
|
156
|
+
const mediaNode = getBinaryNodeChild(productNode, 'media');
|
|
157
|
+
const statusInfoNode = getBinaryNodeChild(productNode, 'status_info');
|
|
163
158
|
const product = {
|
|
164
159
|
id,
|
|
165
160
|
imageUrls: parseImageUrls(mediaNode),
|
|
166
161
|
reviewStatus: {
|
|
167
|
-
whatsapp:
|
|
162
|
+
whatsapp: getBinaryNodeChildString(statusInfoNode, 'status')
|
|
168
163
|
},
|
|
169
164
|
availability: 'in stock',
|
|
170
|
-
name:
|
|
171
|
-
retailerId:
|
|
172
|
-
url:
|
|
173
|
-
description:
|
|
174
|
-
price: +
|
|
175
|
-
currency:
|
|
176
|
-
isHidden
|
|
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
|
|
177
172
|
};
|
|
178
173
|
return product;
|
|
179
174
|
};
|
|
180
|
-
exports.parseProductNode = parseProductNode;
|
|
181
175
|
/**
|
|
182
176
|
* Uploads images not already uploaded to WA's servers
|
|
183
177
|
*/
|
|
184
|
-
async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, timeoutMs = 30000) {
|
|
178
|
+
export async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, timeoutMs = 30000) {
|
|
185
179
|
product = {
|
|
186
180
|
...product,
|
|
187
|
-
images: product.images
|
|
181
|
+
images: product.images
|
|
182
|
+
? await uploadingNecessaryImages(product.images, waUploadToServer, timeoutMs)
|
|
183
|
+
: product.images
|
|
188
184
|
};
|
|
189
185
|
return product;
|
|
190
186
|
}
|
|
191
|
-
exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
|
|
192
187
|
/**
|
|
193
188
|
* Uploads images not already uploaded to WA's servers
|
|
194
189
|
*/
|
|
195
|
-
const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30000) => {
|
|
190
|
+
export const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30000) => {
|
|
196
191
|
const results = await Promise.all(images.map(async (img) => {
|
|
197
192
|
if ('url' in img) {
|
|
198
193
|
const url = img.url.toString();
|
|
@@ -200,35 +195,36 @@ const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30
|
|
|
200
195
|
return { url };
|
|
201
196
|
}
|
|
202
197
|
}
|
|
203
|
-
const { stream } = await
|
|
204
|
-
const hasher =
|
|
205
|
-
const
|
|
198
|
+
const { stream } = await getStream(img);
|
|
199
|
+
const hasher = createHash('sha256');
|
|
200
|
+
const filePath = join(tmpdir(), 'img' + generateMessageIDV2());
|
|
201
|
+
const encFileWriteStream = createWriteStream(filePath);
|
|
206
202
|
for await (const block of stream) {
|
|
207
203
|
hasher.update(block);
|
|
208
|
-
|
|
204
|
+
encFileWriteStream.write(block);
|
|
209
205
|
}
|
|
210
206
|
const sha = hasher.digest('base64');
|
|
211
|
-
const { directPath } = await waUploadToServer(
|
|
207
|
+
const { directPath } = await waUploadToServer(filePath, {
|
|
212
208
|
mediaType: 'product-catalog-image',
|
|
213
209
|
fileEncSha256B64: sha,
|
|
214
210
|
timeoutMs
|
|
215
211
|
});
|
|
216
|
-
|
|
212
|
+
await fs.unlink(filePath).catch(err => console.log('Error deleting temp file ', err));
|
|
213
|
+
return { url: getUrlFromDirectPath(directPath) };
|
|
217
214
|
}));
|
|
218
215
|
return results;
|
|
219
216
|
};
|
|
220
|
-
exports.uploadingNecessaryImages = uploadingNecessaryImages;
|
|
221
217
|
const parseImageUrls = (mediaNode) => {
|
|
222
|
-
const imgNode =
|
|
218
|
+
const imgNode = getBinaryNodeChild(mediaNode, 'image');
|
|
223
219
|
return {
|
|
224
|
-
requested:
|
|
225
|
-
original:
|
|
220
|
+
requested: getBinaryNodeChildString(imgNode, 'request_image_url'),
|
|
221
|
+
original: getBinaryNodeChildString(imgNode, 'original_image_url')
|
|
226
222
|
};
|
|
227
223
|
};
|
|
228
224
|
const parseStatusInfo = (mediaNode) => {
|
|
229
|
-
const node =
|
|
225
|
+
const node = getBinaryNodeChild(mediaNode, 'status_info');
|
|
230
226
|
return {
|
|
231
|
-
status:
|
|
232
|
-
canAppeal:
|
|
227
|
+
status: getBinaryNodeChildString(node, 'status'),
|
|
228
|
+
canAppeal: getBinaryNodeChildString(node, 'can_appeal') === 'true'
|
|
233
229
|
};
|
|
234
|
-
};
|
|
230
|
+
};
|