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.
Files changed (114) hide show
  1. package/LICENSE +3 -2
  2. package/README.md +1001 -232
  3. package/WAProto/index.js +75379 -142631
  4. package/engine-requirements.js +11 -8
  5. package/lib/Defaults/index.js +132 -144
  6. package/lib/Signal/Group/ciphertext-message.js +2 -6
  7. package/lib/Signal/Group/group-session-builder.js +7 -42
  8. package/lib/Signal/Group/group_cipher.js +37 -52
  9. package/lib/Signal/Group/index.js +11 -57
  10. package/lib/Signal/Group/keyhelper.js +7 -45
  11. package/lib/Signal/Group/sender-chain-key.js +7 -16
  12. package/lib/Signal/Group/sender-key-distribution-message.js +8 -12
  13. package/lib/Signal/Group/sender-key-message.js +9 -13
  14. package/lib/Signal/Group/sender-key-name.js +2 -6
  15. package/lib/Signal/Group/sender-key-record.js +9 -22
  16. package/lib/Signal/Group/sender-key-state.js +27 -43
  17. package/lib/Signal/Group/sender-message-key.js +4 -8
  18. package/lib/Signal/libsignal.js +319 -94
  19. package/lib/Signal/lid-mapping.js +224 -139
  20. package/lib/Socket/Client/index.js +2 -19
  21. package/lib/Socket/Client/types.js +10 -0
  22. package/lib/Socket/Client/websocket.js +53 -0
  23. package/lib/Socket/business.js +162 -44
  24. package/lib/Socket/chats.js +477 -442
  25. package/lib/Socket/communities.js +430 -0
  26. package/lib/Socket/groups.js +110 -99
  27. package/lib/Socket/index.js +10 -10
  28. package/lib/Socket/messages-recv.js +878 -552
  29. package/lib/Socket/messages-send.js +859 -428
  30. package/lib/Socket/mex.js +41 -0
  31. package/lib/Socket/newsletter.js +195 -390
  32. package/lib/Socket/socket.js +463 -289
  33. package/lib/Store/index.js +3 -10
  34. package/lib/Store/make-in-memory-store.js +73 -79
  35. package/lib/Store/make-ordered-dictionary.js +4 -7
  36. package/lib/Store/object-repository.js +2 -6
  37. package/lib/Types/Auth.js +1 -2
  38. package/lib/Types/Bussines.js +1 -0
  39. package/lib/Types/Call.js +1 -2
  40. package/lib/Types/Chat.js +7 -4
  41. package/lib/Types/Contact.js +1 -2
  42. package/lib/Types/Events.js +1 -2
  43. package/lib/Types/GroupMetadata.js +1 -2
  44. package/lib/Types/Label.js +2 -5
  45. package/lib/Types/LabelAssociation.js +2 -5
  46. package/lib/Types/Message.js +17 -9
  47. package/lib/Types/Newsletter.js +33 -38
  48. package/lib/Types/Product.js +1 -2
  49. package/lib/Types/Signal.js +1 -2
  50. package/lib/Types/Socket.js +2 -2
  51. package/lib/Types/State.js +12 -2
  52. package/lib/Types/USync.js +1 -2
  53. package/lib/Types/index.js +14 -31
  54. package/lib/Utils/auth-utils.js +228 -145
  55. package/lib/Utils/browser-utils.js +28 -0
  56. package/lib/Utils/business.js +66 -70
  57. package/lib/Utils/chat-utils.js +331 -249
  58. package/lib/Utils/crypto.js +57 -91
  59. package/lib/Utils/decode-wa-message.js +168 -84
  60. package/lib/Utils/event-buffer.js +138 -80
  61. package/lib/Utils/generics.js +180 -297
  62. package/lib/Utils/history.js +83 -49
  63. package/lib/Utils/identity-change-handler.js +48 -0
  64. package/lib/Utils/index.js +19 -33
  65. package/lib/Utils/link-preview.js +14 -23
  66. package/lib/Utils/logger.js +2 -7
  67. package/lib/Utils/lt-hash.js +2 -46
  68. package/lib/Utils/make-mutex.js +24 -35
  69. package/lib/Utils/message-retry-manager.js +224 -0
  70. package/lib/Utils/messages-media.js +501 -496
  71. package/lib/Utils/messages.js +1428 -362
  72. package/lib/Utils/noise-handler.js +145 -100
  73. package/lib/Utils/pre-key-manager.js +105 -0
  74. package/lib/Utils/process-message.js +356 -150
  75. package/lib/Utils/reporting-utils.js +257 -0
  76. package/lib/Utils/signal.js +78 -73
  77. package/lib/Utils/sync-action-utils.js +47 -0
  78. package/lib/Utils/tc-token-utils.js +17 -0
  79. package/lib/Utils/use-multi-file-auth-state.js +32 -34
  80. package/lib/Utils/validate-connection.js +91 -107
  81. package/lib/WABinary/constants.js +1300 -1304
  82. package/lib/WABinary/decode.js +26 -48
  83. package/lib/WABinary/encode.js +109 -155
  84. package/lib/WABinary/generic-utils.js +161 -149
  85. package/lib/WABinary/index.js +5 -21
  86. package/lib/WABinary/jid-utils.js +73 -40
  87. package/lib/WABinary/types.js +1 -2
  88. package/lib/WAM/BinaryInfo.js +2 -6
  89. package/lib/WAM/constants.js +19070 -11568
  90. package/lib/WAM/encode.js +17 -23
  91. package/lib/WAM/index.js +3 -19
  92. package/lib/WAUSync/Protocols/USyncContactProtocol.js +8 -12
  93. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -15
  94. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -13
  95. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -14
  96. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -23
  97. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +13 -9
  98. package/lib/WAUSync/Protocols/index.js +4 -20
  99. package/lib/WAUSync/USyncQuery.js +40 -36
  100. package/lib/WAUSync/USyncUser.js +2 -6
  101. package/lib/WAUSync/index.js +3 -19
  102. package/lib/index.js +11 -44
  103. package/package.json +75 -108
  104. package/lib/Defaults/baileys-version.json +0 -3
  105. package/lib/Defaults/phonenumber-mcc.json +0 -223
  106. package/lib/Signal/Group/queue-job.js +0 -57
  107. package/lib/Socket/Client/abstract-socket-client.js +0 -13
  108. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  109. package/lib/Socket/Client/web-socket-client.js +0 -111
  110. package/lib/Socket/groupStatus.js +0 -637
  111. package/lib/Socket/registration.js +0 -166
  112. package/lib/Socket/usync.js +0 -70
  113. package/lib/Store/make-cache-manager-store.js +0 -83
  114. package/lib/Utils/baileys-event-stream.js +0 -63
@@ -1,28 +1,26 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uploadingNecessaryImages = exports.uploadingNecessaryImagesOfProduct = exports.parseProductNode = exports.toProductNode = exports.parseOrderDetailsNode = exports.parseCollectionsNode = exports.parseCatalogNode = void 0;
4
- const boom_1 = require("@hapi/boom");
5
- const crypto_1 = require("crypto");
6
- const WABinary_1 = require("../WABinary");
7
- const messages_media_1 = require("./messages-media");
8
- const parseCatalogNode = (node) => {
9
- const catalogNode = (0, WABinary_1.getBinaryNodeChild)(node, 'product_catalog');
10
- const products = (0, WABinary_1.getBinaryNodeChildren)(catalogNode, 'product').map(exports.parseProductNode);
11
- const paging = (0, WABinary_1.getBinaryNodeChild)(catalogNode, 'paging');
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
- exports.parseCatalogNode = parseCatalogNode;
20
- const parseCollectionsNode = (node) => {
21
- const collectionsNode = (0, WABinary_1.getBinaryNodeChild)(node, 'collections');
22
- const collections = (0, WABinary_1.getBinaryNodeChildren)(collectionsNode, 'collection').map(collectionNode => {
23
- const id = (0, WABinary_1.getBinaryNodeChildString)(collectionNode, 'id');
24
- const name = (0, WABinary_1.getBinaryNodeChildString)(collectionNode, 'name');
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
- exports.parseCollectionsNode = parseCollectionsNode;
38
- const parseOrderDetailsNode = (node) => {
39
- const orderNode = (0, WABinary_1.getBinaryNodeChild)(node, 'order');
40
- const products = (0, WABinary_1.getBinaryNodeChildren)(orderNode, 'product').map(productNode => {
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: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'id'),
44
- name: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'name'),
45
- imageUrl: (0, WABinary_1.getBinaryNodeChildString)(imageNode, 'url'),
46
- price: +(0, WABinary_1.getBinaryNodeChildString)(productNode, 'price'),
47
- currency: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'currency'),
48
- quantity: +(0, WABinary_1.getBinaryNodeChildString)(productNode, '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 = (0, WABinary_1.getBinaryNodeChild)(orderNode, 'price');
48
+ const priceNode = getBinaryNodeChild(orderNode, 'price');
52
49
  const orderDetails = {
53
50
  price: {
54
- total: +(0, WABinary_1.getBinaryNodeChildString)(priceNode, 'total'),
55
- currency: (0, WABinary_1.getBinaryNodeChildString)(priceNode, '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
- exports.parseOrderDetailsNode = parseOrderDetailsNode;
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 boom_1.Boom('Expected img for product to already be uploaded', { statusCode: 400 });
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
- exports.toProductNode = toProductNode;
158
- const parseProductNode = (productNode) => {
153
+ export const parseProductNode = (productNode) => {
159
154
  const isHidden = productNode.attrs.is_hidden === 'true';
160
- const id = (0, WABinary_1.getBinaryNodeChildString)(productNode, 'id');
161
- const mediaNode = (0, WABinary_1.getBinaryNodeChild)(productNode, 'media');
162
- const statusInfoNode = (0, WABinary_1.getBinaryNodeChild)(productNode, 'status_info');
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: (0, WABinary_1.getBinaryNodeChildString)(statusInfoNode, 'status'),
162
+ whatsapp: getBinaryNodeChildString(statusInfoNode, 'status')
168
163
  },
169
164
  availability: 'in stock',
170
- name: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'name'),
171
- retailerId: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'retailer_id'),
172
- url: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'url'),
173
- description: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'description'),
174
- price: +(0, WABinary_1.getBinaryNodeChildString)(productNode, 'price'),
175
- currency: (0, WABinary_1.getBinaryNodeChildString)(productNode, '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 ? await (0, exports.uploadingNecessaryImages)(product.images, waUploadToServer, timeoutMs) : 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 (0, messages_media_1.getStream)(img);
204
- const hasher = (0, crypto_1.createHash)('sha256');
205
- const contentBlocks = [];
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
- contentBlocks.push(block);
204
+ encFileWriteStream.write(block);
209
205
  }
210
206
  const sha = hasher.digest('base64');
211
- const { directPath } = await waUploadToServer((0, messages_media_1.toReadable)(Buffer.concat(contentBlocks)), {
207
+ const { directPath } = await waUploadToServer(filePath, {
212
208
  mediaType: 'product-catalog-image',
213
209
  fileEncSha256B64: sha,
214
210
  timeoutMs
215
211
  });
216
- return { url: (0, messages_media_1.getUrlFromDirectPath)(directPath) };
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 = (0, WABinary_1.getBinaryNodeChild)(mediaNode, 'image');
218
+ const imgNode = getBinaryNodeChild(mediaNode, 'image');
223
219
  return {
224
- requested: (0, WABinary_1.getBinaryNodeChildString)(imgNode, 'request_image_url'),
225
- original: (0, WABinary_1.getBinaryNodeChildString)(imgNode, 'original_image_url')
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 = (0, WABinary_1.getBinaryNodeChild)(mediaNode, 'status_info');
225
+ const node = getBinaryNodeChild(mediaNode, 'status_info');
230
226
  return {
231
- status: (0, WABinary_1.getBinaryNodeChildString)(node, 'status'),
232
- canAppeal: (0, WABinary_1.getBinaryNodeChildString)(node, 'can_appeal') === 'true',
227
+ status: getBinaryNodeChildString(node, 'status'),
228
+ canAppeal: getBinaryNodeChildString(node, 'can_appeal') === 'true'
233
229
  };
234
- };
230
+ };