@nexustechpro/baileys 2.0.2 → 2.0.6

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 (108) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +924 -1299
  3. package/WAProto/index.js +22 -18
  4. package/lib/Defaults/baileys-version.json +6 -2
  5. package/lib/Defaults/index.js +173 -172
  6. package/lib/Signal/libsignal.js +395 -292
  7. package/lib/Signal/lid-mapping.js +264 -171
  8. package/lib/Socket/Client/index.js +2 -2
  9. package/lib/Socket/Client/types.js +10 -10
  10. package/lib/Socket/Client/websocket.js +45 -310
  11. package/lib/Socket/business.js +375 -375
  12. package/lib/Socket/chats.js +916 -963
  13. package/lib/Socket/communities.js +430 -430
  14. package/lib/Socket/groups.js +342 -342
  15. package/lib/Socket/index.js +21 -22
  16. package/lib/Socket/messages-recv.js +963 -743
  17. package/lib/Socket/messages-send.js +273 -321
  18. package/lib/Socket/mex.js +50 -50
  19. package/lib/Socket/newsletter.js +148 -148
  20. package/lib/Socket/nexus-handler.js +296 -247
  21. package/lib/Socket/registration.js +50 -33
  22. package/lib/Socket/socket.js +872 -1201
  23. package/lib/Store/index.js +5 -5
  24. package/lib/Store/make-cache-manager-store.js +81 -81
  25. package/lib/Store/make-in-memory-store.js +416 -416
  26. package/lib/Store/make-ordered-dictionary.js +81 -81
  27. package/lib/Store/object-repository.js +30 -30
  28. package/lib/Types/Auth.js +1 -1
  29. package/lib/Types/Bussines.js +1 -1
  30. package/lib/Types/Call.js +1 -1
  31. package/lib/Types/Chat.js +7 -7
  32. package/lib/Types/Contact.js +1 -1
  33. package/lib/Types/Events.js +1 -1
  34. package/lib/Types/GroupMetadata.js +1 -1
  35. package/lib/Types/Label.js +24 -24
  36. package/lib/Types/LabelAssociation.js +6 -6
  37. package/lib/Types/Message.js +10 -10
  38. package/lib/Types/Newsletter.js +37 -29
  39. package/lib/Types/Product.js +1 -1
  40. package/lib/Types/Signal.js +1 -1
  41. package/lib/Types/Socket.js +2 -2
  42. package/lib/Types/State.js +55 -12
  43. package/lib/Types/USync.js +1 -1
  44. package/lib/Types/index.js +25 -25
  45. package/lib/Utils/auth-utils.js +264 -256
  46. package/lib/Utils/baileys-event-stream.js +55 -55
  47. package/lib/Utils/browser-utils.js +27 -27
  48. package/lib/Utils/business.js +228 -230
  49. package/lib/Utils/chat-utils.js +726 -764
  50. package/lib/Utils/companion-reg-client-utils.js +34 -0
  51. package/lib/Utils/crypto.js +109 -135
  52. package/lib/Utils/decode-wa-message.js +342 -314
  53. package/lib/Utils/event-buffer.js +547 -547
  54. package/lib/Utils/generics.js +295 -297
  55. package/lib/Utils/history.js +91 -83
  56. package/lib/Utils/index.js +25 -20
  57. package/lib/Utils/key-store.js +17 -0
  58. package/lib/Utils/link-preview.js +107 -98
  59. package/lib/Utils/logger.js +2 -2
  60. package/lib/Utils/lt-hash.js +47 -47
  61. package/lib/Utils/make-mutex.js +39 -39
  62. package/lib/Utils/message-retry-manager.js +148 -148
  63. package/lib/Utils/messages-media.js +579 -535
  64. package/lib/Utils/messages.js +821 -706
  65. package/lib/Utils/noise-handler.js +255 -255
  66. package/lib/Utils/pre-key-manager.js +105 -105
  67. package/lib/Utils/process-message.js +430 -412
  68. package/lib/Utils/reporting-utils.js +155 -0
  69. package/lib/Utils/signal.js +191 -159
  70. package/lib/Utils/sync-action-utils.js +33 -0
  71. package/lib/Utils/tc-token-utils.js +162 -0
  72. package/lib/Utils/use-multi-file-auth-state.js +120 -120
  73. package/lib/Utils/validate-connection.js +194 -194
  74. package/lib/WABinary/constants.js +1306 -1300
  75. package/lib/WABinary/decode.js +237 -237
  76. package/lib/WABinary/encode.js +232 -232
  77. package/lib/WABinary/generic-utils.js +252 -211
  78. package/lib/WABinary/index.js +6 -5
  79. package/lib/WABinary/jid-utils.js +279 -95
  80. package/lib/WABinary/types.js +1 -1
  81. package/lib/WAM/BinaryInfo.js +9 -9
  82. package/lib/WAM/constants.js +22852 -22852
  83. package/lib/WAM/encode.js +149 -149
  84. package/lib/WAM/index.js +3 -3
  85. package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -28
  86. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -53
  87. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -26
  88. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -37
  89. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
  90. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -28
  91. package/lib/WAUSync/Protocols/index.js +4 -4
  92. package/lib/WAUSync/USyncQuery.js +93 -93
  93. package/lib/WAUSync/USyncUser.js +22 -22
  94. package/lib/WAUSync/index.js +3 -3
  95. package/lib/index.js +65 -66
  96. package/package.json +172 -143
  97. package/lib/Signal/Group/ciphertext-message.js +0 -12
  98. package/lib/Signal/Group/group-session-builder.js +0 -30
  99. package/lib/Signal/Group/group_cipher.js +0 -100
  100. package/lib/Signal/Group/index.js +0 -12
  101. package/lib/Signal/Group/keyhelper.js +0 -18
  102. package/lib/Signal/Group/sender-chain-key.js +0 -26
  103. package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
  104. package/lib/Signal/Group/sender-key-message.js +0 -66
  105. package/lib/Signal/Group/sender-key-name.js +0 -48
  106. package/lib/Signal/Group/sender-key-record.js +0 -41
  107. package/lib/Signal/Group/sender-key-state.js +0 -84
  108. package/lib/Signal/Group/sender-message-key.js +0 -26
@@ -1,376 +1,376 @@
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);
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])
14
- .map(key => ({
15
- tag: key,
16
- attrs: {},
17
- content: args[key]
18
- })));
19
- if (args.websites) {
20
- node.push(...args.websites.map(website => ({
21
- tag: 'website',
22
- attrs: {},
23
- content: website
24
- })));
25
- }
26
- if (args.hours) {
27
- node.push({
28
- tag: 'business_hours',
29
- attrs: { timezone: args.hours.timezone },
30
- content: args.hours.days.map(config => {
31
- const base = {
32
- tag: 'business_hours_config',
33
- attrs: { day_of_week: config.day, mode: config.mode }
34
- };
35
- if (config.mode === 'specific_hours') {
36
- return {
37
- ...base,
38
- attrs: {
39
- ...base.attrs,
40
- open_time: config.openTimeInMinutes,
41
- close_time: config.closeTimeInMinutes
42
- }
43
- };
44
- }
45
- return base;
46
- })
47
- });
48
- }
49
- const result = await query({
50
- tag: 'iq',
51
- attrs: {
52
- to: S_WHATSAPP_NET,
53
- type: 'set',
54
- xmlns: 'w:biz'
55
- },
56
- content: [
57
- {
58
- tag: 'business_profile',
59
- attrs: {
60
- v: '3',
61
- mutation_type: 'delta'
62
- },
63
- content: node
64
- }
65
- ]
66
- });
67
- return result;
68
- };
69
- const updateCoverPhoto = async (photo) => {
70
- const { fileSha256, filePath } = await getRawMediaUploadData(photo, 'biz-cover-photo');
71
- const fileSha256B64 = fileSha256.toString('base64');
72
- const { meta_hmac, fbid, ts } = await waUploadToServer(filePath, {
73
- fileEncSha256B64: fileSha256B64,
74
- mediaType: 'biz-cover-photo'
75
- });
76
- await query({
77
- tag: 'iq',
78
- attrs: {
79
- to: S_WHATSAPP_NET,
80
- type: 'set',
81
- xmlns: 'w:biz'
82
- },
83
- content: [
84
- {
85
- tag: 'business_profile',
86
- attrs: {
87
- v: '3',
88
- mutation_type: 'delta'
89
- },
90
- content: [
91
- {
92
- tag: 'cover_photo',
93
- attrs: { id: String(fbid), op: 'update', token: meta_hmac, ts: String(ts) }
94
- }
95
- ]
96
- }
97
- ]
98
- });
99
- return fbid;
100
- };
101
- const removeCoverPhoto = async (id) => {
102
- return await query({
103
- tag: 'iq',
104
- attrs: {
105
- to: S_WHATSAPP_NET,
106
- type: 'set',
107
- xmlns: 'w:biz'
108
- },
109
- content: [
110
- {
111
- tag: 'business_profile',
112
- attrs: {
113
- v: '3',
114
- mutation_type: 'delta'
115
- },
116
- content: [
117
- {
118
- tag: 'cover_photo',
119
- attrs: { op: 'delete', id }
120
- }
121
- ]
122
- }
123
- ]
124
- });
125
- };
126
- const getCatalog = async ({ jid, limit, cursor }) => {
127
- jid = jid || authState.creds.me?.id;
128
- jid = jidNormalizedUser(jid);
129
- const queryParamNodes = [
130
- {
131
- tag: 'limit',
132
- attrs: {},
133
- content: Buffer.from((limit || 10).toString())
134
- },
135
- {
136
- tag: 'width',
137
- attrs: {},
138
- content: Buffer.from('100')
139
- },
140
- {
141
- tag: 'height',
142
- attrs: {},
143
- content: Buffer.from('100')
144
- }
145
- ];
146
- if (cursor) {
147
- queryParamNodes.push({
148
- tag: 'after',
149
- attrs: {},
150
- content: cursor
151
- });
152
- }
153
- const result = await query({
154
- tag: 'iq',
155
- attrs: {
156
- to: S_WHATSAPP_NET,
157
- type: 'get',
158
- xmlns: 'w:biz:catalog'
159
- },
160
- content: [
161
- {
162
- tag: 'product_catalog',
163
- attrs: {
164
- jid,
165
- allow_shop_source: 'true'
166
- },
167
- content: queryParamNodes
168
- }
169
- ]
170
- });
171
- return parseCatalogNode(result);
172
- };
173
- const getCollections = async (jid, limit = 51) => {
174
- jid = jid || authState.creds.me?.id;
175
- jid = jidNormalizedUser(jid);
176
- const result = await query({
177
- tag: 'iq',
178
- attrs: {
179
- to: S_WHATSAPP_NET,
180
- type: 'get',
181
- xmlns: 'w:biz:catalog',
182
- smax_id: '35'
183
- },
184
- content: [
185
- {
186
- tag: 'collections',
187
- attrs: {
188
- biz_jid: jid
189
- },
190
- content: [
191
- {
192
- tag: 'collection_limit',
193
- attrs: {},
194
- content: Buffer.from(limit.toString())
195
- },
196
- {
197
- tag: 'item_limit',
198
- attrs: {},
199
- content: Buffer.from(limit.toString())
200
- },
201
- {
202
- tag: 'width',
203
- attrs: {},
204
- content: Buffer.from('100')
205
- },
206
- {
207
- tag: 'height',
208
- attrs: {},
209
- content: Buffer.from('100')
210
- }
211
- ]
212
- }
213
- ]
214
- });
215
- return parseCollectionsNode(result);
216
- };
217
- const getOrderDetails = async (orderId, tokenBase64) => {
218
- const result = await query({
219
- tag: 'iq',
220
- attrs: {
221
- to: S_WHATSAPP_NET,
222
- type: 'get',
223
- xmlns: 'fb:thrift_iq',
224
- smax_id: '5'
225
- },
226
- content: [
227
- {
228
- tag: 'order',
229
- attrs: {
230
- op: 'get',
231
- id: orderId
232
- },
233
- content: [
234
- {
235
- tag: 'image_dimensions',
236
- attrs: {},
237
- content: [
238
- {
239
- tag: 'width',
240
- attrs: {},
241
- content: Buffer.from('100')
242
- },
243
- {
244
- tag: 'height',
245
- attrs: {},
246
- content: Buffer.from('100')
247
- }
248
- ]
249
- },
250
- {
251
- tag: 'token',
252
- attrs: {},
253
- content: Buffer.from(tokenBase64)
254
- }
255
- ]
256
- }
257
- ]
258
- });
259
- return parseOrderDetailsNode(result);
260
- };
261
- const productUpdate = async (productId, update) => {
262
- update = await uploadingNecessaryImagesOfProduct(update, waUploadToServer);
263
- const editNode = toProductNode(productId, update);
264
- const result = await query({
265
- tag: 'iq',
266
- attrs: {
267
- to: S_WHATSAPP_NET,
268
- type: 'set',
269
- xmlns: 'w:biz:catalog'
270
- },
271
- content: [
272
- {
273
- tag: 'product_catalog_edit',
274
- attrs: { v: '1' },
275
- content: [
276
- editNode,
277
- {
278
- tag: 'width',
279
- attrs: {},
280
- content: '100'
281
- },
282
- {
283
- tag: 'height',
284
- attrs: {},
285
- content: '100'
286
- }
287
- ]
288
- }
289
- ]
290
- });
291
- const productCatalogEditNode = getBinaryNodeChild(result, 'product_catalog_edit');
292
- const productNode = getBinaryNodeChild(productCatalogEditNode, 'product');
293
- return parseProductNode(productNode);
294
- };
295
- const productCreate = async (create) => {
296
- // ensure isHidden is defined
297
- create.isHidden = !!create.isHidden;
298
- create = await uploadingNecessaryImagesOfProduct(create, waUploadToServer);
299
- const createNode = toProductNode(undefined, create);
300
- const result = await query({
301
- tag: 'iq',
302
- attrs: {
303
- to: S_WHATSAPP_NET,
304
- type: 'set',
305
- xmlns: 'w:biz:catalog'
306
- },
307
- content: [
308
- {
309
- tag: 'product_catalog_add',
310
- attrs: { v: '1' },
311
- content: [
312
- createNode,
313
- {
314
- tag: 'width',
315
- attrs: {},
316
- content: '100'
317
- },
318
- {
319
- tag: 'height',
320
- attrs: {},
321
- content: '100'
322
- }
323
- ]
324
- }
325
- ]
326
- });
327
- const productCatalogAddNode = getBinaryNodeChild(result, 'product_catalog_add');
328
- const productNode = getBinaryNodeChild(productCatalogAddNode, 'product');
329
- return parseProductNode(productNode);
330
- };
331
- const productDelete = async (productIds) => {
332
- const result = await query({
333
- tag: 'iq',
334
- attrs: {
335
- to: S_WHATSAPP_NET,
336
- type: 'set',
337
- xmlns: 'w:biz:catalog'
338
- },
339
- content: [
340
- {
341
- tag: 'product_catalog_delete',
342
- attrs: { v: '1' },
343
- content: productIds.map(id => ({
344
- tag: 'product',
345
- attrs: {},
346
- content: [
347
- {
348
- tag: 'id',
349
- attrs: {},
350
- content: Buffer.from(id)
351
- }
352
- ]
353
- }))
354
- }
355
- ]
356
- });
357
- const productCatalogDelNode = getBinaryNodeChild(result, 'product_catalog_delete');
358
- return {
359
- deleted: +(productCatalogDelNode?.attrs.deleted_count || 0)
360
- };
361
- };
362
- return {
363
- ...sock,
364
- logger: config.logger,
365
- getOrderDetails,
366
- getCatalog,
367
- getCollections,
368
- productCreate,
369
- productDelete,
370
- productUpdate,
371
- updateBussinesProfile,
372
- updateCoverPhoto,
373
- removeCoverPhoto
374
- };
375
- };
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);
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])
14
+ .map(key => ({
15
+ tag: key,
16
+ attrs: {},
17
+ content: args[key]
18
+ })));
19
+ if (args.websites) {
20
+ node.push(...args.websites.map(website => ({
21
+ tag: 'website',
22
+ attrs: {},
23
+ content: website
24
+ })));
25
+ }
26
+ if (args.hours) {
27
+ node.push({
28
+ tag: 'business_hours',
29
+ attrs: { timezone: args.hours.timezone },
30
+ content: args.hours.days.map(config => {
31
+ const base = {
32
+ tag: 'business_hours_config',
33
+ attrs: { day_of_week: config.day, mode: config.mode }
34
+ };
35
+ if (config.mode === 'specific_hours') {
36
+ return {
37
+ ...base,
38
+ attrs: {
39
+ ...base.attrs,
40
+ open_time: config.openTimeInMinutes,
41
+ close_time: config.closeTimeInMinutes
42
+ }
43
+ };
44
+ }
45
+ return base;
46
+ })
47
+ });
48
+ }
49
+ const result = await query({
50
+ tag: 'iq',
51
+ attrs: {
52
+ to: S_WHATSAPP_NET,
53
+ type: 'set',
54
+ xmlns: 'w:biz'
55
+ },
56
+ content: [
57
+ {
58
+ tag: 'business_profile',
59
+ attrs: {
60
+ v: '3',
61
+ mutation_type: 'delta'
62
+ },
63
+ content: node
64
+ }
65
+ ]
66
+ });
67
+ return result;
68
+ };
69
+ const updateCoverPhoto = async (photo) => {
70
+ const { fileSha256, filePath } = await getRawMediaUploadData(photo, 'biz-cover-photo');
71
+ const fileSha256B64 = fileSha256.toString('base64');
72
+ const { meta_hmac, fbid, ts } = await waUploadToServer(filePath, {
73
+ fileEncSha256B64: fileSha256B64,
74
+ mediaType: 'biz-cover-photo'
75
+ });
76
+ await query({
77
+ tag: 'iq',
78
+ attrs: {
79
+ to: S_WHATSAPP_NET,
80
+ type: 'set',
81
+ xmlns: 'w:biz'
82
+ },
83
+ content: [
84
+ {
85
+ tag: 'business_profile',
86
+ attrs: {
87
+ v: '3',
88
+ mutation_type: 'delta'
89
+ },
90
+ content: [
91
+ {
92
+ tag: 'cover_photo',
93
+ attrs: { id: String(fbid), op: 'update', token: meta_hmac, ts: String(ts) }
94
+ }
95
+ ]
96
+ }
97
+ ]
98
+ });
99
+ return fbid;
100
+ };
101
+ const removeCoverPhoto = async (id) => {
102
+ return await query({
103
+ tag: 'iq',
104
+ attrs: {
105
+ to: S_WHATSAPP_NET,
106
+ type: 'set',
107
+ xmlns: 'w:biz'
108
+ },
109
+ content: [
110
+ {
111
+ tag: 'business_profile',
112
+ attrs: {
113
+ v: '3',
114
+ mutation_type: 'delta'
115
+ },
116
+ content: [
117
+ {
118
+ tag: 'cover_photo',
119
+ attrs: { op: 'delete', id }
120
+ }
121
+ ]
122
+ }
123
+ ]
124
+ });
125
+ };
126
+ const getCatalog = async ({ jid, limit, cursor }) => {
127
+ jid = jid || authState.creds.me?.id;
128
+ jid = jidNormalizedUser(jid);
129
+ const queryParamNodes = [
130
+ {
131
+ tag: 'limit',
132
+ attrs: {},
133
+ content: Buffer.from((limit || 10).toString())
134
+ },
135
+ {
136
+ tag: 'width',
137
+ attrs: {},
138
+ content: Buffer.from('100')
139
+ },
140
+ {
141
+ tag: 'height',
142
+ attrs: {},
143
+ content: Buffer.from('100')
144
+ }
145
+ ];
146
+ if (cursor) {
147
+ queryParamNodes.push({
148
+ tag: 'after',
149
+ attrs: {},
150
+ content: cursor
151
+ });
152
+ }
153
+ const result = await query({
154
+ tag: 'iq',
155
+ attrs: {
156
+ to: S_WHATSAPP_NET,
157
+ type: 'get',
158
+ xmlns: 'w:biz:catalog'
159
+ },
160
+ content: [
161
+ {
162
+ tag: 'product_catalog',
163
+ attrs: {
164
+ jid,
165
+ allow_shop_source: 'true'
166
+ },
167
+ content: queryParamNodes
168
+ }
169
+ ]
170
+ });
171
+ return parseCatalogNode(result);
172
+ };
173
+ const getCollections = async (jid, limit = 51) => {
174
+ jid = jid || authState.creds.me?.id;
175
+ jid = jidNormalizedUser(jid);
176
+ const result = await query({
177
+ tag: 'iq',
178
+ attrs: {
179
+ to: S_WHATSAPP_NET,
180
+ type: 'get',
181
+ xmlns: 'w:biz:catalog',
182
+ smax_id: '35'
183
+ },
184
+ content: [
185
+ {
186
+ tag: 'collections',
187
+ attrs: {
188
+ biz_jid: jid
189
+ },
190
+ content: [
191
+ {
192
+ tag: 'collection_limit',
193
+ attrs: {},
194
+ content: Buffer.from(limit.toString())
195
+ },
196
+ {
197
+ tag: 'item_limit',
198
+ attrs: {},
199
+ content: Buffer.from(limit.toString())
200
+ },
201
+ {
202
+ tag: 'width',
203
+ attrs: {},
204
+ content: Buffer.from('100')
205
+ },
206
+ {
207
+ tag: 'height',
208
+ attrs: {},
209
+ content: Buffer.from('100')
210
+ }
211
+ ]
212
+ }
213
+ ]
214
+ });
215
+ return parseCollectionsNode(result);
216
+ };
217
+ const getOrderDetails = async (orderId, tokenBase64) => {
218
+ const result = await query({
219
+ tag: 'iq',
220
+ attrs: {
221
+ to: S_WHATSAPP_NET,
222
+ type: 'get',
223
+ xmlns: 'fb:thrift_iq',
224
+ smax_id: '5'
225
+ },
226
+ content: [
227
+ {
228
+ tag: 'order',
229
+ attrs: {
230
+ op: 'get',
231
+ id: orderId
232
+ },
233
+ content: [
234
+ {
235
+ tag: 'image_dimensions',
236
+ attrs: {},
237
+ content: [
238
+ {
239
+ tag: 'width',
240
+ attrs: {},
241
+ content: Buffer.from('100')
242
+ },
243
+ {
244
+ tag: 'height',
245
+ attrs: {},
246
+ content: Buffer.from('100')
247
+ }
248
+ ]
249
+ },
250
+ {
251
+ tag: 'token',
252
+ attrs: {},
253
+ content: Buffer.from(tokenBase64)
254
+ }
255
+ ]
256
+ }
257
+ ]
258
+ });
259
+ return parseOrderDetailsNode(result);
260
+ };
261
+ const productUpdate = async (productId, update) => {
262
+ update = await uploadingNecessaryImagesOfProduct(update, waUploadToServer);
263
+ const editNode = toProductNode(productId, update);
264
+ const result = await query({
265
+ tag: 'iq',
266
+ attrs: {
267
+ to: S_WHATSAPP_NET,
268
+ type: 'set',
269
+ xmlns: 'w:biz:catalog'
270
+ },
271
+ content: [
272
+ {
273
+ tag: 'product_catalog_edit',
274
+ attrs: { v: '1' },
275
+ content: [
276
+ editNode,
277
+ {
278
+ tag: 'width',
279
+ attrs: {},
280
+ content: '100'
281
+ },
282
+ {
283
+ tag: 'height',
284
+ attrs: {},
285
+ content: '100'
286
+ }
287
+ ]
288
+ }
289
+ ]
290
+ });
291
+ const productCatalogEditNode = getBinaryNodeChild(result, 'product_catalog_edit');
292
+ const productNode = getBinaryNodeChild(productCatalogEditNode, 'product');
293
+ return parseProductNode(productNode);
294
+ };
295
+ const productCreate = async (create) => {
296
+ // ensure isHidden is defined
297
+ create.isHidden = !!create.isHidden;
298
+ create = await uploadingNecessaryImagesOfProduct(create, waUploadToServer);
299
+ const createNode = toProductNode(undefined, create);
300
+ const result = await query({
301
+ tag: 'iq',
302
+ attrs: {
303
+ to: S_WHATSAPP_NET,
304
+ type: 'set',
305
+ xmlns: 'w:biz:catalog'
306
+ },
307
+ content: [
308
+ {
309
+ tag: 'product_catalog_add',
310
+ attrs: { v: '1' },
311
+ content: [
312
+ createNode,
313
+ {
314
+ tag: 'width',
315
+ attrs: {},
316
+ content: '100'
317
+ },
318
+ {
319
+ tag: 'height',
320
+ attrs: {},
321
+ content: '100'
322
+ }
323
+ ]
324
+ }
325
+ ]
326
+ });
327
+ const productCatalogAddNode = getBinaryNodeChild(result, 'product_catalog_add');
328
+ const productNode = getBinaryNodeChild(productCatalogAddNode, 'product');
329
+ return parseProductNode(productNode);
330
+ };
331
+ const productDelete = async (productIds) => {
332
+ const result = await query({
333
+ tag: 'iq',
334
+ attrs: {
335
+ to: S_WHATSAPP_NET,
336
+ type: 'set',
337
+ xmlns: 'w:biz:catalog'
338
+ },
339
+ content: [
340
+ {
341
+ tag: 'product_catalog_delete',
342
+ attrs: { v: '1' },
343
+ content: productIds.map(id => ({
344
+ tag: 'product',
345
+ attrs: {},
346
+ content: [
347
+ {
348
+ tag: 'id',
349
+ attrs: {},
350
+ content: Buffer.from(id)
351
+ }
352
+ ]
353
+ }))
354
+ }
355
+ ]
356
+ });
357
+ const productCatalogDelNode = getBinaryNodeChild(result, 'product_catalog_delete');
358
+ return {
359
+ deleted: +(productCatalogDelNode?.attrs.deleted_count || 0)
360
+ };
361
+ };
362
+ return {
363
+ ...sock,
364
+ logger: config.logger,
365
+ getOrderDetails,
366
+ getCatalog,
367
+ getCollections,
368
+ productCreate,
369
+ productDelete,
370
+ productUpdate,
371
+ updateBussinesProfile,
372
+ updateCoverPhoto,
373
+ removeCoverPhoto
374
+ };
375
+ };
376
376
  //# sourceMappingURL=business.js.map