kage-baileys 3.0.6 → 3.2.3

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 (216) hide show
  1. package/Example/connection.cjs +4 -0
  2. package/README.MD +4726 -48
  3. package/WAProto/WAProto.proto +3395 -415
  4. package/WAProto/compat.cjs +12 -0
  5. package/WAProto/index.d.ts +47104 -19888
  6. package/WAProto/index.js +131979 -57361
  7. package/lib/Addon/http-error.js +43 -0
  8. package/lib/Addon/index.js +32 -0
  9. package/lib/Addon/keyed-db.js +250 -0
  10. package/lib/Addon/link-preview.js +82 -0
  11. package/lib/Defaults/baileys-version.json +3 -0
  12. package/lib/Defaults/connection.js +110 -0
  13. package/lib/Defaults/constants.js +156 -0
  14. package/lib/Defaults/history.js +46 -0
  15. package/lib/Defaults/index.js +230 -0
  16. package/lib/Defaults/media.js +104 -0
  17. package/lib/Defaults/phonenumber-mcc.json +223 -0
  18. package/lib/Defaults/prefix.js +44 -0
  19. package/lib/Extensions/business-advanced.js +382 -0
  20. package/lib/Extensions/business.js +159 -0
  21. package/lib/Extensions/chats-advanced.js +1106 -0
  22. package/lib/Extensions/chats.js +349 -0
  23. package/lib/Extensions/communities-advanced.js +430 -0
  24. package/lib/Extensions/community.js +94 -0
  25. package/lib/Extensions/groups-advanced.js +343 -0
  26. package/lib/Extensions/index.js +30 -0
  27. package/lib/Extensions/messages-recv-advanced.js +1690 -0
  28. package/lib/Extensions/messages-send-advanced.js +622 -0
  29. package/lib/Extensions/messages-send.js +1380 -0
  30. package/lib/Extensions/newsletter-advanced.js +228 -0
  31. package/lib/Extensions/newsletter.js +72 -0
  32. package/lib/Extensions/socket.js +389 -0
  33. package/lib/Modded/message_builder.js +2084 -4
  34. package/lib/Signal/Group/ciphertext-message.js +54 -0
  35. package/lib/Signal/Group/group-session-builder.js +124 -0
  36. package/lib/Signal/Group/group_cipher.js +216 -0
  37. package/lib/Signal/Group/index.js +124 -0
  38. package/lib/Signal/Group/keyhelper.js +108 -0
  39. package/lib/Signal/Group/sender-chain-key.js +83 -0
  40. package/lib/Signal/Group/sender-key-distribution-message.js +157 -0
  41. package/lib/Signal/Group/sender-key-message.js +166 -0
  42. package/lib/Signal/Group/sender-key-name.js +130 -0
  43. package/lib/Signal/Group/sender-key-record.js +113 -0
  44. package/lib/Signal/Group/sender-key-state.js +208 -0
  45. package/lib/Signal/Group/sender-message-key.js +82 -0
  46. package/lib/Signal/libsignal.js +935 -0
  47. package/lib/Signal/lid-mapping.js +545 -1
  48. package/lib/Socket/Client/index.js +60 -0
  49. package/lib/Socket/Client/types.js +51 -0
  50. package/lib/Socket/Client/websocket.js +152 -0
  51. package/lib/Socket/business.js +831 -0
  52. package/lib/Socket/chats.js +2535 -49
  53. package/lib/Socket/communities.js +450 -1
  54. package/lib/Socket/community.js +1022 -0
  55. package/lib/Socket/dugong.js +1 -1
  56. package/lib/Socket/groups.js +747 -0
  57. package/lib/Socket/index.js +60 -2
  58. package/lib/Socket/messages-recv.js +3450 -5
  59. package/lib/Socket/messages-send.js +3123 -0
  60. package/lib/Socket/mex.js +126 -1
  61. package/lib/Socket/newsletter.js +465 -0
  62. package/lib/Socket/socket.js +2217 -1
  63. package/lib/Store/index.js +79 -0
  64. package/lib/Store/make-cache-manager-store.js +186 -0
  65. package/lib/Store/make-in-memory-store.js +878 -0
  66. package/lib/Store/make-ordered-dictionary.js +187 -0
  67. package/lib/Store/object-repository.js +78 -0
  68. package/lib/Types/Auth.js +25 -0
  69. package/lib/Types/Bussines.js +25 -1
  70. package/lib/Types/Call.js +25 -0
  71. package/lib/Types/Chat.js +39 -0
  72. package/lib/Types/Contact.js +25 -0
  73. package/lib/Types/Events.js +25 -0
  74. package/lib/Types/GroupMetadata.js +25 -0
  75. package/lib/Types/Label.js +76 -0
  76. package/lib/Types/LabelAssociation.js +40 -0
  77. package/lib/Types/Message.js +57 -0
  78. package/lib/Types/Mex.js +56 -1
  79. package/lib/Types/MexUpdates.js +46 -0
  80. package/lib/Types/Newsletter.js +56 -0
  81. package/lib/Types/Product.js +25 -0
  82. package/lib/Types/RichType.js +23 -0
  83. package/lib/Types/Signal.js +25 -0
  84. package/lib/Types/Socket.js +25 -0
  85. package/lib/Types/State.js +92 -0
  86. package/lib/Types/USync.js +25 -0
  87. package/lib/Types/index.js +133 -0
  88. package/lib/Utils/auth-utils.js +703 -0
  89. package/lib/Utils/automation-tools.js +51 -16
  90. package/lib/Utils/baileys-event-stream.js +146 -0
  91. package/lib/Utils/browser-utils.js +95 -0
  92. package/lib/Utils/business.js +525 -0
  93. package/lib/Utils/chat-utils.js +1861 -0
  94. package/lib/Utils/companion-reg-client-utils.js +55 -1
  95. package/lib/Utils/crypto.js +355 -0
  96. package/lib/Utils/decode-wa-message.js +709 -0
  97. package/lib/Utils/event-buffer.js +1323 -8
  98. package/lib/Utils/generics.js +945 -1
  99. package/lib/Utils/history.js +266 -0
  100. package/lib/Utils/identity-change-handler.js +62 -1
  101. package/lib/Utils/index.js +114 -0
  102. package/lib/Utils/link-preview.js +179 -0
  103. package/lib/Utils/logger.js +42 -0
  104. package/lib/Utils/lt-hash.js +73 -0
  105. package/lib/Utils/make-mutex.js +104 -0
  106. package/lib/Utils/message-inspector.js +110 -0
  107. package/lib/Utils/message-retry-manager.js +507 -2
  108. package/lib/Utils/messages-media.js +1931 -1
  109. package/lib/Utils/messages.js +3748 -0
  110. package/lib/Utils/noise-handler.js +423 -0
  111. package/lib/Utils/offline-node-processor.js +53 -1
  112. package/lib/Utils/pre-key-manager.js +255 -1
  113. package/lib/Utils/process-message.js +1592 -0
  114. package/lib/Utils/reporting-utils.js +272 -1
  115. package/lib/Utils/rich-message-utils.js +377 -0
  116. package/lib/Utils/rich-messages.js +1 -1
  117. package/lib/Utils/signal.js +437 -0
  118. package/lib/Utils/stanza-ack.js +51 -1
  119. package/lib/Utils/status-refresh.js +37 -0
  120. package/lib/Utils/status-tools.js +4 -2
  121. package/lib/Utils/sync-action-utils.js +63 -1
  122. package/lib/Utils/tc-token-utils.js +185 -1
  123. package/lib/Utils/terminal-banner.js +31 -0
  124. package/lib/Utils/use-multi-file-auth-state.js +271 -0
  125. package/lib/Utils/use-single-file-auth-state.js +108 -0
  126. package/lib/Utils/use-sqlite-auth-state.js +142 -0
  127. package/lib/Utils/validate-connection.js +497 -1
  128. package/lib/Utils/view-once-compat.js +13 -5
  129. package/lib/VoIP/audio-feeder.js +150 -0
  130. package/lib/VoIP/index.js +289 -0
  131. package/lib/VoIP/relay-transport.js +608 -0
  132. package/lib/VoIP/signaling.js +583 -0
  133. package/lib/VoIP/types.js +30 -0
  134. package/lib/VoIP/wasm-engine.js +1261 -2
  135. package/lib/VoIP/worker-bootstrap.js +1090 -2
  136. package/lib/WABinary/constants.js +2805 -0
  137. package/lib/WABinary/decode.js +649 -2
  138. package/lib/WABinary/encode.js +564 -2
  139. package/lib/WABinary/generic-utils.js +401 -0
  140. package/lib/WABinary/index.js +82 -0
  141. package/lib/WABinary/jid-utils.js +290 -0
  142. package/lib/WABinary/types.js +25 -0
  143. package/lib/WAM/BinaryInfo.js +50 -0
  144. package/lib/WAM/constants.js +45747 -0
  145. package/lib/WAM/encode.js +393 -0
  146. package/lib/WAM/index.js +78 -0
  147. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +135 -0
  148. package/lib/WAUSync/Protocols/USyncContactProtocol.js +110 -0
  149. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +142 -0
  150. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +85 -0
  151. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +69 -0
  152. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +107 -0
  153. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +38 -1
  154. package/lib/WAUSync/Protocols/index.js +83 -0
  155. package/lib/WAUSync/USyncQuery.js +241 -2
  156. package/lib/WAUSync/USyncUser.js +86 -0
  157. package/lib/WAUSync/index.js +78 -0
  158. package/lib/assets/wasm/loader.js +1875 -1
  159. package/lib/assets/wasm/worker-modules.js +11047 -1
  160. package/lib/index.d.ts +126 -0
  161. package/lib/index.js +53 -21
  162. package/lib/index.mjs +437 -0
  163. package/licenses/upstream-MIT.txt +22 -0
  164. package/maintenance/api-coverage.json +1642 -0
  165. package/maintenance/archivos-sha256.json +207 -0
  166. package/maintenance/consumer-validation.log +3 -0
  167. package/maintenance/dependency-audit.json +4 -4
  168. package/maintenance/extension-inventory.json +57 -0
  169. package/maintenance/protocol-update.json +1101 -0
  170. package/maintenance/protocol-wire-audit.json +4 -0
  171. package/maintenance/reference-socket-surface.json +209 -0
  172. package/maintenance/resumen-validacion.json +50 -0
  173. package/maintenance/validation.log +2725 -0
  174. package/maintenance/verification.json +566 -0
  175. package/package.json +107 -9
  176. package/scripts/check-imports.cjs +10 -0
  177. package/scripts/check-package.cjs +40 -0
  178. package/scripts/check-syntax.cjs +1 -1
  179. package/scripts/generate-protobuf.cjs +6 -1
  180. package/scripts/generate-public-types.cjs +9 -0
  181. package/scripts/kage-base64-fix.cjs +45 -0
  182. package/scripts/maintenance.cjs +10 -0
  183. package/test/advanced.test.cjs +24 -0
  184. package/test/base64-fix.test.cjs +49 -0
  185. package/test/maintenance.test.cjs +1 -1
  186. package/test/npm-publication.test.cjs +141 -0
  187. package/test/recepcion-reparada.test.cjs +98 -0
  188. package/test/resilience-binary.test.cjs +69 -0
  189. package/test/resilience-transport.test.cjs +34 -0
  190. package/test/types.test.ts +5 -0
  191. package/test/upgrade.test.cjs +104 -0
  192. package/tsconfig.json +20 -0
  193. package/WAProto/p.html +0 -1
  194. package/lib/KageExtra/Modded/message_builder.js +0 -2330
  195. package/lib/KageExtra/VoIP/audio-feeder.js +0 -136
  196. package/lib/KageExtra/VoIP/index.js +0 -282
  197. package/lib/KageExtra/VoIP/relay-transport.js +0 -559
  198. package/lib/KageExtra/VoIP/signaling.js +0 -603
  199. package/lib/KageExtra/VoIP/types.js +0 -17
  200. package/lib/KageExtra/VoIP/wasm-engine.js +0 -1214
  201. package/lib/KageExtra/VoIP/worker-bootstrap.js +0 -1042
  202. package/lib/KageExtra/assets/wasm/loader.js +0 -5
  203. package/lib/KageExtra/assets/wasm/whatsapp.wasm +0 -0
  204. package/lib/KageExtra/assets/wasm/worker-modules.js +0 -273
  205. package/lib/KageExtra/index.js +0 -3
  206. package/lib/KageExtra/package.json +0 -1
  207. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -53
  208. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -24
  209. package/maintenance/revision-full-check.txt +0 -1097
  210. package/maintenance/revision-library-tests.tap +0 -1088
  211. package/maintenance/revision-protobuf.txt +0 -5
  212. package/maintenance/revision-syntax.txt +0 -5
  213. package/maintenance/schema-coverage.json +0 -23
  214. package/maintenance/schema-merge.json +0 -30
  215. package/maintenance/validation-node20.txt +0 -191
  216. package/maintenance/validation-node22.txt +0 -237
@@ -258,3 +258,834 @@ const makeBusinessSocket = (config) => {
258
258
  };
259
259
  };
260
260
  exports.makeBusinessSocket = makeBusinessSocket;
261
+
262
+ // Kage: compatibilidad de API.
263
+ const __kageModule24 = (() => {
264
+ const module = { exports: {} }; const exports = module.exports;
265
+ "use strict"
266
+
267
+ Object.defineProperty(exports, "__esModule", { value: true })
268
+
269
+ const {
270
+ toProductNode,
271
+ parseCatalogNode,
272
+ parseCollectionsNode,
273
+ parseOrderDetailsNode,
274
+ getRawMediaUploadData,
275
+ uploadingNecessaryImagesOfProduct
276
+ } = require("../Utils")
277
+ const {
278
+ S_WHATSAPP_NET,
279
+ jidNormalizedUser,
280
+ getBinaryNodeChild
281
+ } = require("../WABinary")
282
+ const { makeMessagesRecvSocket } = require("./messages-recv")
283
+
284
+ const makeBusinessSocket = (config) => {
285
+ const suki = makeMessagesRecvSocket(config)
286
+ const {
287
+ authState,
288
+ query,
289
+ waUploadToServer
290
+ } = suki
291
+
292
+ const updateBussinesProfile = async (args) => {
293
+ const node = []
294
+ const simpleFields = ['address', 'email', 'description']
295
+
296
+ node.push(...simpleFields
297
+ .filter(key => args[key])
298
+ .map(key => ({
299
+ tag: key,
300
+ attrs: {},
301
+ content: args[key]
302
+ })))
303
+
304
+ if (args.websites) {
305
+
306
+ node.push(...args.websites.map(website => ({
307
+ tag: 'website',
308
+ attrs: {},
309
+ content: website
310
+ })))
311
+ }
312
+
313
+ if (args.hours) {
314
+
315
+ node.push({
316
+ tag: 'business_hours',
317
+ attrs: { timezone: args.hours.timezone },
318
+ content: args.hours.days.map(config => {
319
+ const base = {
320
+ tag: 'business_hours_config',
321
+ attrs: { day_of_week: config.day, mode: config.mode }
322
+ }
323
+
324
+ if (config.mode === 'specific_hours') {
325
+ return {
326
+ ...base,
327
+ attrs: {
328
+ ...base.attrs,
329
+ open_time: config.openTimeInMinutes,
330
+ close_time: config.closeTimeInMinutes
331
+ }
332
+ }
333
+ }
334
+
335
+ return base
336
+ })
337
+ })
338
+ }
339
+
340
+ const result = await query({
341
+ tag: 'iq',
342
+ attrs: {
343
+ to: S_WHATSAPP_NET,
344
+ type: 'set',
345
+ xmlns: 'w:biz'
346
+ },
347
+ content: [
348
+ {
349
+ tag: 'business_profile',
350
+ attrs: {
351
+ v: '3',
352
+ mutation_type: 'delta'
353
+ },
354
+ content: node
355
+ }
356
+ ]
357
+ })
358
+
359
+ return result
360
+ }
361
+
362
+ const updateCoverPhoto = async (photo) => {
363
+ const { fileSha256, filePath } = await getRawMediaUploadData(photo, 'biz-cover-photo')
364
+ const fileSha256B64 = fileSha256.toString('base64')
365
+
366
+ const { meta_hmac, fbid, ts } = await waUploadToServer(filePath, {
367
+ fileEncSha256B64: fileSha256B64,
368
+ mediaType: 'biz-cover-photo'
369
+ })
370
+
371
+ await query({
372
+ tag: 'iq',
373
+ attrs: {
374
+ to: S_WHATSAPP_NET,
375
+ type: 'set',
376
+ xmlns: 'w:biz'
377
+ },
378
+ content: [
379
+ {
380
+ tag: 'business_profile',
381
+ attrs: {
382
+ v: '3',
383
+ mutation_type: 'delta'
384
+ },
385
+ content: [
386
+ {
387
+ tag: 'cover_photo',
388
+ attrs: { id: String(fbid), op: 'update', token: meta_hmac, ts: String(ts) }
389
+ }
390
+ ]
391
+ }
392
+ ]
393
+ })
394
+
395
+ return fbid
396
+ }
397
+
398
+ const removeCoverPhoto = async (id) => {
399
+ return await query({
400
+ tag: 'iq',
401
+ attrs: {
402
+ to: S_WHATSAPP_NET,
403
+ type: 'set',
404
+ xmlns: 'w:biz'
405
+ },
406
+ content: [
407
+ {
408
+ tag: 'business_profile',
409
+ attrs: {
410
+ v: '3',
411
+ mutation_type: 'delta'
412
+ },
413
+ content: [
414
+ {
415
+ tag: 'cover_photo',
416
+ attrs: { op: 'delete', id }
417
+ }
418
+ ]
419
+ }
420
+ ]
421
+ })
422
+ }
423
+
424
+ const getCatalog = async ({ jid, limit, cursor }) => {
425
+ jid = jid || authState.creds.me?.id
426
+ jid = jidNormalizedUser(jid)
427
+
428
+ const queryParamNodes = [
429
+ {
430
+ tag: 'limit',
431
+ attrs: {},
432
+ content: Buffer.from((limit || 10).toString())
433
+ },
434
+ {
435
+ tag: 'width',
436
+ attrs: {},
437
+ content: Buffer.from('100')
438
+ },
439
+ {
440
+ tag: 'height',
441
+ attrs: {},
442
+ content: Buffer.from('100')
443
+ },
444
+ ]
445
+
446
+ if (cursor) {
447
+ queryParamNodes.push({
448
+ tag: 'after',
449
+ attrs: {},
450
+ content: cursor
451
+ })
452
+ }
453
+
454
+ const result = await query({
455
+ tag: 'iq',
456
+ attrs: {
457
+ to: S_WHATSAPP_NET,
458
+ type: 'get',
459
+ xmlns: 'w:biz:catalog'
460
+ },
461
+ content: [
462
+ {
463
+ tag: 'product_catalog',
464
+ attrs: {
465
+ jid,
466
+ 'allow_shop_source': 'true'
467
+ },
468
+ content: queryParamNodes
469
+ }
470
+ ]
471
+ })
472
+
473
+ return parseCatalogNode(result)
474
+ }
475
+
476
+ const getCollections = async (jid, limit = 51) => {
477
+ jid = jid || authState.creds.me?.id
478
+ jid = jidNormalizedUser(jid)
479
+
480
+ const result = await query({
481
+ tag: 'iq',
482
+ attrs: {
483
+ to: S_WHATSAPP_NET,
484
+ type: 'get',
485
+ xmlns: 'w:biz:catalog',
486
+ 'smax_id': '35'
487
+ },
488
+ content: [
489
+ {
490
+ tag: 'collections',
491
+ attrs: {
492
+ 'biz_jid': jid,
493
+ },
494
+ content: [
495
+ {
496
+ tag: 'collection_limit',
497
+ attrs: {},
498
+ content: Buffer.from(limit.toString())
499
+ },
500
+ {
501
+ tag: 'item_limit',
502
+ attrs: {},
503
+ content: Buffer.from(limit.toString())
504
+ },
505
+ {
506
+ tag: 'width',
507
+ attrs: {},
508
+ content: Buffer.from('100')
509
+ },
510
+ {
511
+ tag: 'height',
512
+ attrs: {},
513
+ content: Buffer.from('100')
514
+ }
515
+ ]
516
+ }
517
+ ]
518
+ })
519
+
520
+ return parseCollectionsNode(result)
521
+ }
522
+
523
+ const getOrderDetails = async (orderId, tokenBase64) => {
524
+ const result = await query({
525
+ tag: 'iq',
526
+ attrs: {
527
+ to: S_WHATSAPP_NET,
528
+ type: 'get',
529
+ xmlns: 'fb:thrift_iq',
530
+ 'smax_id': '5'
531
+ },
532
+ content: [
533
+ {
534
+ tag: 'order',
535
+ attrs: {
536
+ op: 'get',
537
+ id: orderId
538
+ },
539
+ content: [
540
+ {
541
+ tag: 'image_dimensions',
542
+ attrs: {},
543
+ content: [
544
+ {
545
+ tag: 'width',
546
+ attrs: {},
547
+ content: Buffer.from('100')
548
+ },
549
+ {
550
+ tag: 'height',
551
+ attrs: {},
552
+ content: Buffer.from('100')
553
+ }
554
+ ]
555
+ },
556
+ {
557
+ tag: 'token',
558
+ attrs: {},
559
+ content: Buffer.from(tokenBase64)
560
+ }
561
+ ]
562
+ }
563
+ ]
564
+ })
565
+
566
+ return parseOrderDetailsNode(result)
567
+ }
568
+
569
+ const productUpdate = async (productId, update) => {
570
+ update = await uploadingNecessaryImagesOfProduct(update, waUploadToServer)
571
+ const editNode = toProductNode(productId, update)
572
+
573
+ const result = await query({
574
+ tag: 'iq',
575
+ attrs: {
576
+ to: S_WHATSAPP_NET,
577
+ type: 'set',
578
+ xmlns: 'w:biz:catalog'
579
+ },
580
+ content: [
581
+ {
582
+ tag: 'product_catalog_edit',
583
+ attrs: { v: '1' },
584
+ content: [
585
+ editNode,
586
+ {
587
+ tag: 'width',
588
+ attrs: {},
589
+ content: '100'
590
+ },
591
+ {
592
+ tag: 'height',
593
+ attrs: {},
594
+ content: '100'
595
+ }
596
+ ]
597
+ }
598
+ ]
599
+ })
600
+ const productCatalogEditNode = getBinaryNodeChild(result, 'product_catalog_edit')
601
+ const productNode = getBinaryNodeChild(productCatalogEditNode, 'product')
602
+ return parseProductNode(productNode)
603
+ }
604
+
605
+ const productCreate = async (create) => {
606
+ // ensure isHidden is defined
607
+ create.isHidden = !!create.isHidden
608
+ create = await uploadingNecessaryImagesOfProduct(create, waUploadToServer)
609
+ const createNode = toProductNode(undefined, create)
610
+
611
+ const result = await query({
612
+ tag: 'iq',
613
+ attrs: {
614
+ to: S_WHATSAPP_NET,
615
+ type: 'set',
616
+ xmlns: 'w:biz:catalog'
617
+ },
618
+ content: [
619
+ {
620
+ tag: 'product_catalog_add',
621
+ attrs: { v: '1' },
622
+ content: [
623
+ createNode,
624
+ {
625
+ tag: 'width',
626
+ attrs: {},
627
+ content: '100'
628
+ },
629
+ {
630
+ tag: 'height',
631
+ attrs: {},
632
+ content: '100'
633
+ }
634
+ ]
635
+ }
636
+ ]
637
+ })
638
+ const productCatalogAddNode = getBinaryNodeChild(result, 'product_catalog_add')
639
+ const productNode = getBinaryNodeChild(productCatalogAddNode, 'product')
640
+
641
+ return parseProductNode(productNode)
642
+ }
643
+
644
+ const productDelete = async (productIds) => {
645
+ const result = await query({
646
+ tag: 'iq',
647
+ attrs: {
648
+ to: S_WHATSAPP_NET,
649
+ type: 'set',
650
+ xmlns: 'w:biz:catalog'
651
+ },
652
+ content: [
653
+ {
654
+ tag: 'product_catalog_delete',
655
+ attrs: { v: '1' },
656
+ content: productIds.map(id => ({
657
+ tag: 'product',
658
+ attrs: {},
659
+ content: [
660
+ {
661
+ tag: 'id',
662
+ attrs: {},
663
+ content: Buffer.from(id)
664
+ }
665
+ ]
666
+ }))
667
+ }
668
+ ]
669
+ })
670
+ const productCatalogDelNode = getBinaryNodeChild(result, 'product_catalog_delete')
671
+ return {
672
+ deleted: +(productCatalogDelNode?.attrs?.deleted_count || 0)
673
+ }
674
+ }
675
+ return {
676
+ ...suki,
677
+ logger: config.logger,
678
+ getOrderDetails,
679
+ getCatalog,
680
+ getCollections,
681
+ productCreate,
682
+ productDelete,
683
+ productUpdate,
684
+ updateBussinesProfile,
685
+ updateCoverPhoto,
686
+ removeCoverPhoto
687
+ }
688
+ }
689
+
690
+ module.exports = {
691
+ makeBusinessSocket
692
+ }
693
+ return module.exports;
694
+ })();
695
+ for (const key of Object.keys(__kageModule24)) {
696
+ if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule24[key]});
697
+ }
698
+
699
+ // Kage: funciones avanzadas.
700
+ const __kageModule130 = (() => {
701
+ const module = { exports: {} }; const exports = module.exports;
702
+ "use strict";
703
+ Object.defineProperty(exports, "__esModule", { value: true });
704
+ exports.makeBusinessSocket = void 0;
705
+ const index_js_1 = require("../Utils/index.js");
706
+ const business_js_1 = require("../Utils/business.js");
707
+ const index_js_2 = require("../WABinary/index.js");
708
+ const generic_utils_js_1 = require("../WABinary/generic-utils.js");
709
+ const messages_recv_js_1 = require("./messages-recv.js");
710
+ const makeBusinessSocket = (config) => {
711
+ const sock = (0, messages_recv_js_1.makeMessagesRecvSocket)(config);
712
+ const { authState, query, waUploadToServer } = sock;
713
+ const updateBussinesProfile = async (args) => {
714
+ const node = [];
715
+ const simpleFields = ['address', 'email', 'description'];
716
+ node.push(...simpleFields
717
+ .filter(key => args[key] !== undefined && args[key] !== null)
718
+ .map(key => ({
719
+ tag: key,
720
+ attrs: {},
721
+ content: args[key]
722
+ })));
723
+ if (args.websites !== undefined) {
724
+ node.push(...args.websites.map(website => ({
725
+ tag: 'website',
726
+ attrs: {},
727
+ content: website
728
+ })));
729
+ }
730
+ if (args.hours !== undefined) {
731
+ node.push({
732
+ tag: 'business_hours',
733
+ attrs: { timezone: args.hours.timezone },
734
+ content: args.hours.days.map(dayConfig => {
735
+ const base = {
736
+ tag: 'business_hours_config',
737
+ attrs: {
738
+ day_of_week: dayConfig.day,
739
+ mode: dayConfig.mode
740
+ }
741
+ };
742
+ if (dayConfig.mode === 'specific_hours') {
743
+ return {
744
+ ...base,
745
+ attrs: {
746
+ ...base.attrs,
747
+ open_time: dayConfig.openTimeInMinutes,
748
+ close_time: dayConfig.closeTimeInMinutes
749
+ }
750
+ };
751
+ }
752
+ return base;
753
+ })
754
+ });
755
+ }
756
+ const result = await query({
757
+ tag: 'iq',
758
+ attrs: {
759
+ to: index_js_2.S_WHATSAPP_NET,
760
+ type: 'set',
761
+ xmlns: 'w:biz'
762
+ },
763
+ content: [
764
+ {
765
+ tag: 'business_profile',
766
+ attrs: {
767
+ v: '3',
768
+ mutation_type: 'delta'
769
+ },
770
+ content: node
771
+ }
772
+ ]
773
+ });
774
+ return result;
775
+ };
776
+ const updateCoverPhoto = async (photo) => {
777
+ const { fileSha256, filePath } = await (0, index_js_1.getRawMediaUploadData)(photo, 'biz-cover-photo');
778
+ const fileSha256B64 = fileSha256.toString('base64');
779
+ const { meta_hmac, fbid, ts } = await waUploadToServer(filePath, {
780
+ fileEncSha256B64: fileSha256B64,
781
+ mediaType: 'biz-cover-photo'
782
+ });
783
+ await query({
784
+ tag: 'iq',
785
+ attrs: {
786
+ to: index_js_2.S_WHATSAPP_NET,
787
+ type: 'set',
788
+ xmlns: 'w:biz'
789
+ },
790
+ content: [
791
+ {
792
+ tag: 'business_profile',
793
+ attrs: {
794
+ v: '3',
795
+ mutation_type: 'delta'
796
+ },
797
+ content: [
798
+ {
799
+ tag: 'cover_photo',
800
+ attrs: { id: String(fbid), op: 'update', token: meta_hmac, ts: String(ts) }
801
+ }
802
+ ]
803
+ }
804
+ ]
805
+ });
806
+ return fbid;
807
+ };
808
+ const removeCoverPhoto = async (id) => {
809
+ return await query({
810
+ tag: 'iq',
811
+ attrs: {
812
+ to: index_js_2.S_WHATSAPP_NET,
813
+ type: 'set',
814
+ xmlns: 'w:biz'
815
+ },
816
+ content: [
817
+ {
818
+ tag: 'business_profile',
819
+ attrs: {
820
+ v: '3',
821
+ mutation_type: 'delta'
822
+ },
823
+ content: [
824
+ {
825
+ tag: 'cover_photo',
826
+ attrs: { op: 'delete', id }
827
+ }
828
+ ]
829
+ }
830
+ ]
831
+ });
832
+ };
833
+ const getCatalog = async ({ jid, limit, cursor }) => {
834
+ jid = jid || authState.creds.me?.id;
835
+ jid = (0, index_js_2.jidNormalizedUser)(jid);
836
+ const queryParamNodes = [
837
+ {
838
+ tag: 'limit',
839
+ attrs: {},
840
+ content: Buffer.from((limit || 10).toString())
841
+ },
842
+ {
843
+ tag: 'width',
844
+ attrs: {},
845
+ content: Buffer.from('100')
846
+ },
847
+ {
848
+ tag: 'height',
849
+ attrs: {},
850
+ content: Buffer.from('100')
851
+ }
852
+ ];
853
+ if (cursor) {
854
+ queryParamNodes.push({
855
+ tag: 'after',
856
+ attrs: {},
857
+ content: cursor
858
+ });
859
+ }
860
+ const result = await query({
861
+ tag: 'iq',
862
+ attrs: {
863
+ to: index_js_2.S_WHATSAPP_NET,
864
+ type: 'get',
865
+ xmlns: 'w:biz:catalog'
866
+ },
867
+ content: [
868
+ {
869
+ tag: 'product_catalog',
870
+ attrs: {
871
+ jid,
872
+ allow_shop_source: 'true'
873
+ },
874
+ content: queryParamNodes
875
+ }
876
+ ]
877
+ });
878
+ return (0, business_js_1.parseCatalogNode)(result);
879
+ };
880
+ const getCollections = async (jid, limit = 51) => {
881
+ jid = jid || authState.creds.me?.id;
882
+ jid = (0, index_js_2.jidNormalizedUser)(jid);
883
+ const result = await query({
884
+ tag: 'iq',
885
+ attrs: {
886
+ to: index_js_2.S_WHATSAPP_NET,
887
+ type: 'get',
888
+ xmlns: 'w:biz:catalog',
889
+ smax_id: '35'
890
+ },
891
+ content: [
892
+ {
893
+ tag: 'collections',
894
+ attrs: {
895
+ biz_jid: jid
896
+ },
897
+ content: [
898
+ {
899
+ tag: 'collection_limit',
900
+ attrs: {},
901
+ content: Buffer.from(limit.toString())
902
+ },
903
+ {
904
+ tag: 'item_limit',
905
+ attrs: {},
906
+ content: Buffer.from(limit.toString())
907
+ },
908
+ {
909
+ tag: 'width',
910
+ attrs: {},
911
+ content: Buffer.from('100')
912
+ },
913
+ {
914
+ tag: 'height',
915
+ attrs: {},
916
+ content: Buffer.from('100')
917
+ }
918
+ ]
919
+ }
920
+ ]
921
+ });
922
+ return (0, business_js_1.parseCollectionsNode)(result);
923
+ };
924
+ const getOrderDetails = async (orderId, tokenBase64) => {
925
+ const result = await query({
926
+ tag: 'iq',
927
+ attrs: {
928
+ to: index_js_2.S_WHATSAPP_NET,
929
+ type: 'get',
930
+ xmlns: 'fb:thrift_iq',
931
+ smax_id: '5'
932
+ },
933
+ content: [
934
+ {
935
+ tag: 'order',
936
+ attrs: {
937
+ op: 'get',
938
+ id: orderId
939
+ },
940
+ content: [
941
+ {
942
+ tag: 'image_dimensions',
943
+ attrs: {},
944
+ content: [
945
+ {
946
+ tag: 'width',
947
+ attrs: {},
948
+ content: Buffer.from('100')
949
+ },
950
+ {
951
+ tag: 'height',
952
+ attrs: {},
953
+ content: Buffer.from('100')
954
+ }
955
+ ]
956
+ },
957
+ {
958
+ tag: 'token',
959
+ attrs: {},
960
+ content: Buffer.from(tokenBase64)
961
+ }
962
+ ]
963
+ }
964
+ ]
965
+ });
966
+ return (0, business_js_1.parseOrderDetailsNode)(result);
967
+ };
968
+ const productUpdate = async (productId, update) => {
969
+ update = await (0, business_js_1.uploadingNecessaryImagesOfProduct)(update, waUploadToServer);
970
+ const editNode = (0, business_js_1.toProductNode)(productId, update);
971
+ const result = await query({
972
+ tag: 'iq',
973
+ attrs: {
974
+ to: index_js_2.S_WHATSAPP_NET,
975
+ type: 'set',
976
+ xmlns: 'w:biz:catalog'
977
+ },
978
+ content: [
979
+ {
980
+ tag: 'product_catalog_edit',
981
+ attrs: { v: '1' },
982
+ content: [
983
+ editNode,
984
+ {
985
+ tag: 'width',
986
+ attrs: {},
987
+ content: '100'
988
+ },
989
+ {
990
+ tag: 'height',
991
+ attrs: {},
992
+ content: '100'
993
+ }
994
+ ]
995
+ }
996
+ ]
997
+ });
998
+ const productCatalogEditNode = (0, generic_utils_js_1.getBinaryNodeChild)(result, 'product_catalog_edit');
999
+ const productNode = (0, generic_utils_js_1.getBinaryNodeChild)(productCatalogEditNode, 'product');
1000
+ return (0, business_js_1.parseProductNode)(productNode);
1001
+ };
1002
+ const productCreate = async (create) => {
1003
+ // ensure isHidden is defined
1004
+ create.isHidden = !!create.isHidden;
1005
+ create = await (0, business_js_1.uploadingNecessaryImagesOfProduct)(create, waUploadToServer);
1006
+ const createNode = (0, business_js_1.toProductNode)(undefined, create);
1007
+ const result = await query({
1008
+ tag: 'iq',
1009
+ attrs: {
1010
+ to: index_js_2.S_WHATSAPP_NET,
1011
+ type: 'set',
1012
+ xmlns: 'w:biz:catalog'
1013
+ },
1014
+ content: [
1015
+ {
1016
+ tag: 'product_catalog_add',
1017
+ attrs: { v: '1' },
1018
+ content: [
1019
+ createNode,
1020
+ {
1021
+ tag: 'width',
1022
+ attrs: {},
1023
+ content: '100'
1024
+ },
1025
+ {
1026
+ tag: 'height',
1027
+ attrs: {},
1028
+ content: '100'
1029
+ }
1030
+ ]
1031
+ }
1032
+ ]
1033
+ });
1034
+ const productCatalogAddNode = (0, generic_utils_js_1.getBinaryNodeChild)(result, 'product_catalog_add');
1035
+ const productNode = (0, generic_utils_js_1.getBinaryNodeChild)(productCatalogAddNode, 'product');
1036
+ return (0, business_js_1.parseProductNode)(productNode);
1037
+ };
1038
+ const productDelete = async (productIds) => {
1039
+ const result = await query({
1040
+ tag: 'iq',
1041
+ attrs: {
1042
+ to: index_js_2.S_WHATSAPP_NET,
1043
+ type: 'set',
1044
+ xmlns: 'w:biz:catalog'
1045
+ },
1046
+ content: [
1047
+ {
1048
+ tag: 'product_catalog_delete',
1049
+ attrs: { v: '1' },
1050
+ content: productIds.map(id => ({
1051
+ tag: 'product',
1052
+ attrs: {},
1053
+ content: [
1054
+ {
1055
+ tag: 'id',
1056
+ attrs: {},
1057
+ content: Buffer.from(id)
1058
+ }
1059
+ ]
1060
+ }))
1061
+ }
1062
+ ]
1063
+ });
1064
+ const productCatalogDelNode = (0, generic_utils_js_1.getBinaryNodeChild)(result, 'product_catalog_delete');
1065
+ return {
1066
+ deleted: +(productCatalogDelNode?.attrs.deleted_count || 0)
1067
+ };
1068
+ };
1069
+ return {
1070
+ ...sock,
1071
+ logger: config.logger,
1072
+ getOrderDetails,
1073
+ getCatalog,
1074
+ getCollections,
1075
+ productCreate,
1076
+ productDelete,
1077
+ productUpdate,
1078
+ updateBussinesProfile,
1079
+ updateBusinessProfile: updateBussinesProfile,
1080
+ updateCoverPhoto,
1081
+ removeCoverPhoto
1082
+ };
1083
+ };
1084
+ exports.makeBusinessSocket = makeBusinessSocket;
1085
+
1086
+ return module.exports;
1087
+ })();
1088
+ for (const key of Object.keys(__kageModule130)) {
1089
+ if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule130[key]});
1090
+ }
1091
+ Object.defineProperty(exports, Symbol.for('kage.advanced'), {value:__kageModule130, configurable:true});