violetics 7.0.1-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 -146
  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 -418
  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 +884 -561
  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 +465 -315
  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 -152
  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 -47
  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 +35 -45
  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 +74 -107
  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 -118
  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,17 +1,134 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeBusinessSocket = void 0;
4
- const business_1 = require("../Utils/business");
5
- const WABinary_1 = require("../WABinary");
6
- const generic_utils_1 = require("../WABinary/generic-utils");
7
- const messages_recv_1 = require("./messages-recv");
8
- const makeBusinessSocket = (config) => {
9
- const sock = (0, messages_recv_1.makeMessagesRecvSocket)(config);
1
+ import { getRawMediaUploadData } from '../Utils/index.js';
2
+ import { parseCatalogNode, parseCollectionsNode, parseOrderDetailsNode, parseProductNode, toProductNode, uploadingNecessaryImagesOfProduct } from '../Utils/business.js';
3
+ import { jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
4
+ import { getBinaryNodeChild } from '../WABinary/generic-utils.js';
5
+ import { makeMessagesRecvSocket } from './messages-recv.js';
6
+ export const makeBusinessSocket = (config) => {
7
+ const sock = makeMessagesRecvSocket(config);
10
8
  const { authState, query, waUploadToServer } = sock;
9
+ const updateBussinesProfile = async (args) => {
10
+ const node = [];
11
+ const simpleFields = ['address', 'email', 'description'];
12
+ node.push(...simpleFields
13
+ .filter(key => args[key] !== undefined && args[key] !== null)
14
+ .map(key => ({
15
+ tag: key,
16
+ attrs: {},
17
+ content: args[key]
18
+ })));
19
+ if (args.websites !== undefined) {
20
+ node.push(...args.websites.map(website => ({
21
+ tag: 'website',
22
+ attrs: {},
23
+ content: website
24
+ })));
25
+ }
26
+ if (args.hours !== undefined) {
27
+ node.push({
28
+ tag: 'business_hours',
29
+ attrs: { timezone: args.hours.timezone },
30
+ content: args.hours.days.map(dayConfig => {
31
+ const base = {
32
+ tag: 'business_hours_config',
33
+ attrs: {
34
+ day_of_week: dayConfig.day,
35
+ mode: dayConfig.mode
36
+ }
37
+ };
38
+ if (dayConfig.mode === 'specific_hours') {
39
+ return {
40
+ ...base,
41
+ attrs: {
42
+ ...base.attrs,
43
+ open_time: dayConfig.openTimeInMinutes,
44
+ close_time: dayConfig.closeTimeInMinutes
45
+ }
46
+ };
47
+ }
48
+ return base;
49
+ })
50
+ });
51
+ }
52
+ const result = await query({
53
+ tag: 'iq',
54
+ attrs: {
55
+ to: S_WHATSAPP_NET,
56
+ type: 'set',
57
+ xmlns: 'w:biz'
58
+ },
59
+ content: [
60
+ {
61
+ tag: 'business_profile',
62
+ attrs: {
63
+ v: '3',
64
+ mutation_type: 'delta'
65
+ },
66
+ content: node
67
+ }
68
+ ]
69
+ });
70
+ return result;
71
+ };
72
+ const updateCoverPhoto = async (photo) => {
73
+ const { fileSha256, filePath } = await getRawMediaUploadData(photo, 'biz-cover-photo');
74
+ const fileSha256B64 = fileSha256.toString('base64');
75
+ const { meta_hmac, fbid, ts } = await waUploadToServer(filePath, {
76
+ fileEncSha256B64: fileSha256B64,
77
+ mediaType: 'biz-cover-photo'
78
+ });
79
+ await query({
80
+ tag: 'iq',
81
+ attrs: {
82
+ to: S_WHATSAPP_NET,
83
+ type: 'set',
84
+ xmlns: 'w:biz'
85
+ },
86
+ content: [
87
+ {
88
+ tag: 'business_profile',
89
+ attrs: {
90
+ v: '3',
91
+ mutation_type: 'delta'
92
+ },
93
+ content: [
94
+ {
95
+ tag: 'cover_photo',
96
+ attrs: { id: String(fbid), op: 'update', token: meta_hmac, ts: String(ts) }
97
+ }
98
+ ]
99
+ }
100
+ ]
101
+ });
102
+ return fbid;
103
+ };
104
+ const removeCoverPhoto = async (id) => {
105
+ return await query({
106
+ tag: 'iq',
107
+ attrs: {
108
+ to: S_WHATSAPP_NET,
109
+ type: 'set',
110
+ xmlns: 'w:biz'
111
+ },
112
+ content: [
113
+ {
114
+ tag: 'business_profile',
115
+ attrs: {
116
+ v: '3',
117
+ mutation_type: 'delta'
118
+ },
119
+ content: [
120
+ {
121
+ tag: 'cover_photo',
122
+ attrs: { op: 'delete', id }
123
+ }
124
+ ]
125
+ }
126
+ ]
127
+ });
128
+ };
11
129
  const getCatalog = async ({ jid, limit, cursor }) => {
12
- var _a;
13
- jid = jid || ((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id);
14
- jid = (0, WABinary_1.jidNormalizedUser)(jid);
130
+ jid = jid || authState.creds.me?.id;
131
+ jid = jidNormalizedUser(jid);
15
132
  const queryParamNodes = [
16
133
  {
17
134
  tag: 'limit',
@@ -27,7 +144,7 @@ const makeBusinessSocket = (config) => {
27
144
  tag: 'height',
28
145
  attrs: {},
29
146
  content: Buffer.from('100')
30
- },
147
+ }
31
148
  ];
32
149
  if (cursor) {
33
150
  queryParamNodes.push({
@@ -39,7 +156,7 @@ const makeBusinessSocket = (config) => {
39
156
  const result = await query({
40
157
  tag: 'iq',
41
158
  attrs: {
42
- to: WABinary_1.S_WHATSAPP_NET,
159
+ to: S_WHATSAPP_NET,
43
160
  type: 'get',
44
161
  xmlns: 'w:biz:catalog'
45
162
  },
@@ -48,31 +165,30 @@ const makeBusinessSocket = (config) => {
48
165
  tag: 'product_catalog',
49
166
  attrs: {
50
167
  jid,
51
- 'allow_shop_source': 'true'
168
+ allow_shop_source: 'true'
52
169
  },
53
170
  content: queryParamNodes
54
171
  }
55
172
  ]
56
173
  });
57
- return (0, business_1.parseCatalogNode)(result);
174
+ return parseCatalogNode(result);
58
175
  };
59
176
  const getCollections = async (jid, limit = 51) => {
60
- var _a;
61
- jid = jid || ((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id);
62
- jid = (0, WABinary_1.jidNormalizedUser)(jid);
177
+ jid = jid || authState.creds.me?.id;
178
+ jid = jidNormalizedUser(jid);
63
179
  const result = await query({
64
180
  tag: 'iq',
65
181
  attrs: {
66
- to: WABinary_1.S_WHATSAPP_NET,
182
+ to: S_WHATSAPP_NET,
67
183
  type: 'get',
68
184
  xmlns: 'w:biz:catalog',
69
- 'smax_id': '35'
185
+ smax_id: '35'
70
186
  },
71
187
  content: [
72
188
  {
73
189
  tag: 'collections',
74
190
  attrs: {
75
- 'biz_jid': jid,
191
+ biz_jid: jid
76
192
  },
77
193
  content: [
78
194
  {
@@ -99,16 +215,16 @@ const makeBusinessSocket = (config) => {
99
215
  }
100
216
  ]
101
217
  });
102
- return (0, business_1.parseCollectionsNode)(result);
218
+ return parseCollectionsNode(result);
103
219
  };
104
220
  const getOrderDetails = async (orderId, tokenBase64) => {
105
221
  const result = await query({
106
222
  tag: 'iq',
107
223
  attrs: {
108
- to: WABinary_1.S_WHATSAPP_NET,
224
+ to: S_WHATSAPP_NET,
109
225
  type: 'get',
110
226
  xmlns: 'fb:thrift_iq',
111
- 'smax_id': '5'
227
+ smax_id: '5'
112
228
  },
113
229
  content: [
114
230
  {
@@ -143,15 +259,15 @@ const makeBusinessSocket = (config) => {
143
259
  }
144
260
  ]
145
261
  });
146
- return (0, business_1.parseOrderDetailsNode)(result);
262
+ return parseOrderDetailsNode(result);
147
263
  };
148
264
  const productUpdate = async (productId, update) => {
149
- update = await (0, business_1.uploadingNecessaryImagesOfProduct)(update, waUploadToServer);
150
- const editNode = (0, business_1.toProductNode)(productId, update);
265
+ update = await uploadingNecessaryImagesOfProduct(update, waUploadToServer);
266
+ const editNode = toProductNode(productId, update);
151
267
  const result = await query({
152
268
  tag: 'iq',
153
269
  attrs: {
154
- to: WABinary_1.S_WHATSAPP_NET,
270
+ to: S_WHATSAPP_NET,
155
271
  type: 'set',
156
272
  xmlns: 'w:biz:catalog'
157
273
  },
@@ -175,19 +291,19 @@ const makeBusinessSocket = (config) => {
175
291
  }
176
292
  ]
177
293
  });
178
- const productCatalogEditNode = (0, generic_utils_1.getBinaryNodeChild)(result, 'product_catalog_edit');
179
- const productNode = (0, generic_utils_1.getBinaryNodeChild)(productCatalogEditNode, 'product');
180
- return (0, business_1.parseProductNode)(productNode);
294
+ const productCatalogEditNode = getBinaryNodeChild(result, 'product_catalog_edit');
295
+ const productNode = getBinaryNodeChild(productCatalogEditNode, 'product');
296
+ return parseProductNode(productNode);
181
297
  };
182
298
  const productCreate = async (create) => {
183
299
  // ensure isHidden is defined
184
300
  create.isHidden = !!create.isHidden;
185
- create = await (0, business_1.uploadingNecessaryImagesOfProduct)(create, waUploadToServer);
186
- const createNode = (0, business_1.toProductNode)(undefined, create);
301
+ create = await uploadingNecessaryImagesOfProduct(create, waUploadToServer);
302
+ const createNode = toProductNode(undefined, create);
187
303
  const result = await query({
188
304
  tag: 'iq',
189
305
  attrs: {
190
- to: WABinary_1.S_WHATSAPP_NET,
306
+ to: S_WHATSAPP_NET,
191
307
  type: 'set',
192
308
  xmlns: 'w:biz:catalog'
193
309
  },
@@ -211,15 +327,15 @@ const makeBusinessSocket = (config) => {
211
327
  }
212
328
  ]
213
329
  });
214
- const productCatalogAddNode = (0, generic_utils_1.getBinaryNodeChild)(result, 'product_catalog_add');
215
- const productNode = (0, generic_utils_1.getBinaryNodeChild)(productCatalogAddNode, 'product');
216
- return (0, business_1.parseProductNode)(productNode);
330
+ const productCatalogAddNode = getBinaryNodeChild(result, 'product_catalog_add');
331
+ const productNode = getBinaryNodeChild(productCatalogAddNode, 'product');
332
+ return parseProductNode(productNode);
217
333
  };
218
334
  const productDelete = async (productIds) => {
219
335
  const result = await query({
220
336
  tag: 'iq',
221
337
  attrs: {
222
- to: WABinary_1.S_WHATSAPP_NET,
338
+ to: S_WHATSAPP_NET,
223
339
  type: 'set',
224
340
  xmlns: 'w:biz:catalog'
225
341
  },
@@ -241,9 +357,9 @@ const makeBusinessSocket = (config) => {
241
357
  }
242
358
  ]
243
359
  });
244
- const productCatalogDelNode = (0, generic_utils_1.getBinaryNodeChild)(result, 'product_catalog_delete');
360
+ const productCatalogDelNode = getBinaryNodeChild(result, 'product_catalog_delete');
245
361
  return {
246
- deleted: +((productCatalogDelNode === null || productCatalogDelNode === void 0 ? void 0 : productCatalogDelNode.attrs.deleted_count) || 0)
362
+ deleted: +(productCatalogDelNode?.attrs.deleted_count || 0)
247
363
  };
248
364
  };
249
365
  return {
@@ -254,7 +370,9 @@ const makeBusinessSocket = (config) => {
254
370
  getCollections,
255
371
  productCreate,
256
372
  productDelete,
257
- productUpdate
373
+ productUpdate,
374
+ updateBussinesProfile,
375
+ updateCoverPhoto,
376
+ removeCoverPhoto
258
377
  };
259
- };
260
- exports.makeBusinessSocket = makeBusinessSocket;
378
+ };