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
@@ -0,0 +1,382 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.attachAdvanced = void 0;
4
+ const index_js_1 = require("../Utils/index.js");
5
+ const business_js_1 = require("../Utils/business.js");
6
+ const index_js_2 = require("../WABinary/index.js");
7
+ const generic_utils_js_1 = require("../WABinary/generic-utils.js");
8
+ const attachAdvanced = (base, config) => {
9
+ const sock = base;
10
+ const { authState, query, waUploadToServer } = sock;
11
+ const updateBussinesProfile = async (args) => {
12
+ const node = [];
13
+ const simpleFields = ['address', 'email', 'description'];
14
+ node.push(...simpleFields
15
+ .filter(key => args[key] !== undefined && args[key] !== null)
16
+ .map(key => ({
17
+ tag: key,
18
+ attrs: {},
19
+ content: args[key]
20
+ })));
21
+ if (args.websites !== undefined) {
22
+ node.push(...args.websites.map(website => ({
23
+ tag: 'website',
24
+ attrs: {},
25
+ content: website
26
+ })));
27
+ }
28
+ if (args.hours !== undefined) {
29
+ node.push({
30
+ tag: 'business_hours',
31
+ attrs: { timezone: args.hours.timezone },
32
+ content: args.hours.days.map(dayConfig => {
33
+ const base = {
34
+ tag: 'business_hours_config',
35
+ attrs: {
36
+ day_of_week: dayConfig.day,
37
+ mode: dayConfig.mode
38
+ }
39
+ };
40
+ if (dayConfig.mode === 'specific_hours') {
41
+ return {
42
+ ...base,
43
+ attrs: {
44
+ ...base.attrs,
45
+ open_time: dayConfig.openTimeInMinutes,
46
+ close_time: dayConfig.closeTimeInMinutes
47
+ }
48
+ };
49
+ }
50
+ return base;
51
+ })
52
+ });
53
+ }
54
+ const result = await query({
55
+ tag: 'iq',
56
+ attrs: {
57
+ to: index_js_2.S_WHATSAPP_NET,
58
+ type: 'set',
59
+ xmlns: 'w:biz'
60
+ },
61
+ content: [
62
+ {
63
+ tag: 'business_profile',
64
+ attrs: {
65
+ v: '3',
66
+ mutation_type: 'delta'
67
+ },
68
+ content: node
69
+ }
70
+ ]
71
+ });
72
+ return result;
73
+ };
74
+ const updateCoverPhoto = async (photo) => {
75
+ const { fileSha256, filePath } = await (0, index_js_1.getRawMediaUploadData)(photo, 'biz-cover-photo');
76
+ const fileSha256B64 = fileSha256.toString('base64');
77
+ const { meta_hmac, fbid, ts } = await waUploadToServer(filePath, {
78
+ fileEncSha256B64: fileSha256B64,
79
+ mediaType: 'biz-cover-photo'
80
+ });
81
+ await query({
82
+ tag: 'iq',
83
+ attrs: {
84
+ to: index_js_2.S_WHATSAPP_NET,
85
+ type: 'set',
86
+ xmlns: 'w:biz'
87
+ },
88
+ content: [
89
+ {
90
+ tag: 'business_profile',
91
+ attrs: {
92
+ v: '3',
93
+ mutation_type: 'delta'
94
+ },
95
+ content: [
96
+ {
97
+ tag: 'cover_photo',
98
+ attrs: { id: String(fbid), op: 'update', token: meta_hmac, ts: String(ts) }
99
+ }
100
+ ]
101
+ }
102
+ ]
103
+ });
104
+ return fbid;
105
+ };
106
+ const removeCoverPhoto = async (id) => {
107
+ return await query({
108
+ tag: 'iq',
109
+ attrs: {
110
+ to: index_js_2.S_WHATSAPP_NET,
111
+ type: 'set',
112
+ xmlns: 'w:biz'
113
+ },
114
+ content: [
115
+ {
116
+ tag: 'business_profile',
117
+ attrs: {
118
+ v: '3',
119
+ mutation_type: 'delta'
120
+ },
121
+ content: [
122
+ {
123
+ tag: 'cover_photo',
124
+ attrs: { op: 'delete', id }
125
+ }
126
+ ]
127
+ }
128
+ ]
129
+ });
130
+ };
131
+ const getCatalog = async ({ jid, limit, cursor }) => {
132
+ jid = jid || authState.creds.me?.id;
133
+ jid = (0, index_js_2.jidNormalizedUser)(jid);
134
+ const queryParamNodes = [
135
+ {
136
+ tag: 'limit',
137
+ attrs: {},
138
+ content: Buffer.from((limit || 10).toString())
139
+ },
140
+ {
141
+ tag: 'width',
142
+ attrs: {},
143
+ content: Buffer.from('100')
144
+ },
145
+ {
146
+ tag: 'height',
147
+ attrs: {},
148
+ content: Buffer.from('100')
149
+ }
150
+ ];
151
+ if (cursor) {
152
+ queryParamNodes.push({
153
+ tag: 'after',
154
+ attrs: {},
155
+ content: cursor
156
+ });
157
+ }
158
+ const result = await query({
159
+ tag: 'iq',
160
+ attrs: {
161
+ to: index_js_2.S_WHATSAPP_NET,
162
+ type: 'get',
163
+ xmlns: 'w:biz:catalog'
164
+ },
165
+ content: [
166
+ {
167
+ tag: 'product_catalog',
168
+ attrs: {
169
+ jid,
170
+ allow_shop_source: 'true'
171
+ },
172
+ content: queryParamNodes
173
+ }
174
+ ]
175
+ });
176
+ return (0, business_js_1.parseCatalogNode)(result);
177
+ };
178
+ const getCollections = async (jid, limit = 51) => {
179
+ jid = jid || authState.creds.me?.id;
180
+ jid = (0, index_js_2.jidNormalizedUser)(jid);
181
+ const result = await query({
182
+ tag: 'iq',
183
+ attrs: {
184
+ to: index_js_2.S_WHATSAPP_NET,
185
+ type: 'get',
186
+ xmlns: 'w:biz:catalog',
187
+ smax_id: '35'
188
+ },
189
+ content: [
190
+ {
191
+ tag: 'collections',
192
+ attrs: {
193
+ biz_jid: jid
194
+ },
195
+ content: [
196
+ {
197
+ tag: 'collection_limit',
198
+ attrs: {},
199
+ content: Buffer.from(limit.toString())
200
+ },
201
+ {
202
+ tag: 'item_limit',
203
+ attrs: {},
204
+ content: Buffer.from(limit.toString())
205
+ },
206
+ {
207
+ tag: 'width',
208
+ attrs: {},
209
+ content: Buffer.from('100')
210
+ },
211
+ {
212
+ tag: 'height',
213
+ attrs: {},
214
+ content: Buffer.from('100')
215
+ }
216
+ ]
217
+ }
218
+ ]
219
+ });
220
+ return (0, business_js_1.parseCollectionsNode)(result);
221
+ };
222
+ const getOrderDetails = async (orderId, tokenBase64) => {
223
+ const result = await query({
224
+ tag: 'iq',
225
+ attrs: {
226
+ to: index_js_2.S_WHATSAPP_NET,
227
+ type: 'get',
228
+ xmlns: 'fb:thrift_iq',
229
+ smax_id: '5'
230
+ },
231
+ content: [
232
+ {
233
+ tag: 'order',
234
+ attrs: {
235
+ op: 'get',
236
+ id: orderId
237
+ },
238
+ content: [
239
+ {
240
+ tag: 'image_dimensions',
241
+ attrs: {},
242
+ content: [
243
+ {
244
+ tag: 'width',
245
+ attrs: {},
246
+ content: Buffer.from('100')
247
+ },
248
+ {
249
+ tag: 'height',
250
+ attrs: {},
251
+ content: Buffer.from('100')
252
+ }
253
+ ]
254
+ },
255
+ {
256
+ tag: 'token',
257
+ attrs: {},
258
+ content: Buffer.from(tokenBase64)
259
+ }
260
+ ]
261
+ }
262
+ ]
263
+ });
264
+ return (0, business_js_1.parseOrderDetailsNode)(result);
265
+ };
266
+ const productUpdate = async (productId, update) => {
267
+ update = await (0, business_js_1.uploadingNecessaryImagesOfProduct)(update, waUploadToServer);
268
+ const editNode = (0, business_js_1.toProductNode)(productId, update);
269
+ const result = await query({
270
+ tag: 'iq',
271
+ attrs: {
272
+ to: index_js_2.S_WHATSAPP_NET,
273
+ type: 'set',
274
+ xmlns: 'w:biz:catalog'
275
+ },
276
+ content: [
277
+ {
278
+ tag: 'product_catalog_edit',
279
+ attrs: { v: '1' },
280
+ content: [
281
+ editNode,
282
+ {
283
+ tag: 'width',
284
+ attrs: {},
285
+ content: '100'
286
+ },
287
+ {
288
+ tag: 'height',
289
+ attrs: {},
290
+ content: '100'
291
+ }
292
+ ]
293
+ }
294
+ ]
295
+ });
296
+ const productCatalogEditNode = (0, generic_utils_js_1.getBinaryNodeChild)(result, 'product_catalog_edit');
297
+ const productNode = (0, generic_utils_js_1.getBinaryNodeChild)(productCatalogEditNode, 'product');
298
+ return (0, business_js_1.parseProductNode)(productNode);
299
+ };
300
+ const productCreate = async (create) => {
301
+ // ensure isHidden is defined
302
+ create.isHidden = !!create.isHidden;
303
+ create = await (0, business_js_1.uploadingNecessaryImagesOfProduct)(create, waUploadToServer);
304
+ const createNode = (0, business_js_1.toProductNode)(undefined, create);
305
+ const result = await query({
306
+ tag: 'iq',
307
+ attrs: {
308
+ to: index_js_2.S_WHATSAPP_NET,
309
+ type: 'set',
310
+ xmlns: 'w:biz:catalog'
311
+ },
312
+ content: [
313
+ {
314
+ tag: 'product_catalog_add',
315
+ attrs: { v: '1' },
316
+ content: [
317
+ createNode,
318
+ {
319
+ tag: 'width',
320
+ attrs: {},
321
+ content: '100'
322
+ },
323
+ {
324
+ tag: 'height',
325
+ attrs: {},
326
+ content: '100'
327
+ }
328
+ ]
329
+ }
330
+ ]
331
+ });
332
+ const productCatalogAddNode = (0, generic_utils_js_1.getBinaryNodeChild)(result, 'product_catalog_add');
333
+ const productNode = (0, generic_utils_js_1.getBinaryNodeChild)(productCatalogAddNode, 'product');
334
+ return (0, business_js_1.parseProductNode)(productNode);
335
+ };
336
+ const productDelete = async (productIds) => {
337
+ const result = await query({
338
+ tag: 'iq',
339
+ attrs: {
340
+ to: index_js_2.S_WHATSAPP_NET,
341
+ type: 'set',
342
+ xmlns: 'w:biz:catalog'
343
+ },
344
+ content: [
345
+ {
346
+ tag: 'product_catalog_delete',
347
+ attrs: { v: '1' },
348
+ content: productIds.map(id => ({
349
+ tag: 'product',
350
+ attrs: {},
351
+ content: [
352
+ {
353
+ tag: 'id',
354
+ attrs: {},
355
+ content: Buffer.from(id)
356
+ }
357
+ ]
358
+ }))
359
+ }
360
+ ]
361
+ });
362
+ const productCatalogDelNode = (0, generic_utils_js_1.getBinaryNodeChild)(result, 'product_catalog_delete');
363
+ return {
364
+ deleted: +(productCatalogDelNode?.attrs.deleted_count || 0)
365
+ };
366
+ };
367
+ return {
368
+ ...sock,
369
+ logger: config.logger,
370
+ getOrderDetails,
371
+ getCatalog,
372
+ getCollections,
373
+ productCreate,
374
+ productDelete,
375
+ productUpdate,
376
+ updateBussinesProfile,
377
+ updateBusinessProfile: updateBussinesProfile,
378
+ updateCoverPhoto,
379
+ removeCoverPhoto
380
+ };
381
+ };
382
+ exports.attachAdvanced = attachAdvanced;
@@ -0,0 +1,159 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", { value: true })
3
+ const {
4
+ toProductNode,
5
+ parseCatalogNode,
6
+ parseCollectionsNode,
7
+ parseOrderDetailsNode,
8
+ getRawMediaUploadData,
9
+ uploadingNecessaryImagesOfProduct
10
+ } = require("../Utils")
11
+ const {
12
+ S_WHATSAPP_NET,
13
+ jidNormalizedUser,
14
+ getBinaryNodeChild
15
+ } = require("../WABinary")
16
+ const { makeMessagesRecvSocket } = require("../Socket/messages-recv")
17
+
18
+ exports.attach = function(base, config) {
19
+ const suki = base
20
+ const {
21
+ authState,
22
+ query,
23
+ waUploadToServer
24
+ } = suki
25
+ const updateBussinesProfile = (base["updateBussinesProfile"] !== undefined ? base["updateBussinesProfile"] : (async (args) => {
26
+ const node = []
27
+ const simpleFields = ['address', 'email', 'description']
28
+
29
+ node.push(...simpleFields
30
+ .filter(key => args[key])
31
+ .map(key => ({
32
+ tag: key,
33
+ attrs: {},
34
+ content: args[key]
35
+ })))
36
+
37
+ if (args.websites) {
38
+
39
+ node.push(...args.websites.map(website => ({
40
+ tag: 'website',
41
+ attrs: {},
42
+ content: website
43
+ })))
44
+ }
45
+
46
+ if (args.hours) {
47
+
48
+ node.push({
49
+ tag: 'business_hours',
50
+ attrs: { timezone: args.hours.timezone },
51
+ content: args.hours.days.map(config => {
52
+ const base = {
53
+ tag: 'business_hours_config',
54
+ attrs: { day_of_week: config.day, mode: config.mode }
55
+ }
56
+
57
+ if (config.mode === 'specific_hours') {
58
+ return {
59
+ ...base,
60
+ attrs: {
61
+ ...base.attrs,
62
+ open_time: config.openTimeInMinutes,
63
+ close_time: config.closeTimeInMinutes
64
+ }
65
+ }
66
+ }
67
+
68
+ return base
69
+ })
70
+ })
71
+ }
72
+
73
+ const result = await query({
74
+ tag: 'iq',
75
+ attrs: {
76
+ to: S_WHATSAPP_NET,
77
+ type: 'set',
78
+ xmlns: 'w:biz'
79
+ },
80
+ content: [
81
+ {
82
+ tag: 'business_profile',
83
+ attrs: {
84
+ v: '3',
85
+ mutation_type: 'delta'
86
+ },
87
+ content: node
88
+ }
89
+ ]
90
+ })
91
+
92
+ return result
93
+ }))
94
+ const updateCoverPhoto = (base["updateCoverPhoto"] !== undefined ? base["updateCoverPhoto"] : (async (photo) => {
95
+ const { fileSha256, filePath } = await getRawMediaUploadData(photo, 'biz-cover-photo')
96
+ const fileSha256B64 = fileSha256.toString('base64')
97
+
98
+ const { meta_hmac, fbid, ts } = await waUploadToServer(filePath, {
99
+ fileEncSha256B64: fileSha256B64,
100
+ mediaType: 'biz-cover-photo'
101
+ })
102
+
103
+ await query({
104
+ tag: 'iq',
105
+ attrs: {
106
+ to: S_WHATSAPP_NET,
107
+ type: 'set',
108
+ xmlns: 'w:biz'
109
+ },
110
+ content: [
111
+ {
112
+ tag: 'business_profile',
113
+ attrs: {
114
+ v: '3',
115
+ mutation_type: 'delta'
116
+ },
117
+ content: [
118
+ {
119
+ tag: 'cover_photo',
120
+ attrs: { id: String(fbid), op: 'update', token: meta_hmac, ts: String(ts) }
121
+ }
122
+ ]
123
+ }
124
+ ]
125
+ })
126
+
127
+ return fbid
128
+ }))
129
+ const removeCoverPhoto = (base["removeCoverPhoto"] !== undefined ? base["removeCoverPhoto"] : (async (id) => {
130
+ return await query({
131
+ tag: 'iq',
132
+ attrs: {
133
+ to: S_WHATSAPP_NET,
134
+ type: 'set',
135
+ xmlns: 'w:biz'
136
+ },
137
+ content: [
138
+ {
139
+ tag: 'business_profile',
140
+ attrs: {
141
+ v: '3',
142
+ mutation_type: 'delta'
143
+ },
144
+ content: [
145
+ {
146
+ tag: 'cover_photo',
147
+ attrs: { op: 'delete', id }
148
+ }
149
+ ]
150
+ }
151
+ ]
152
+ })
153
+ }))
154
+ return {
155
+ updateBussinesProfile,
156
+ updateCoverPhoto,
157
+ removeCoverPhoto
158
+ };
159
+ };