@bellaxchuu/flowred 0.8.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 (142) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +214 -0
  3. package/WAProto/GenerateStatics.sh +3 -0
  4. package/WAProto/WAProto.proto +6902 -0
  5. package/WAProto/fix-imports.js +85 -0
  6. package/WAProto/index.js +242946 -0
  7. package/engine-requirements.js +10 -0
  8. package/lib/Defaults/index.js +190 -0
  9. package/lib/Defaults/phonenumber-mcc.json +223 -0
  10. package/lib/Signal/Group/ciphertext-message.js +15 -0
  11. package/lib/Signal/Group/group-session-builder.js +92 -0
  12. package/lib/Signal/Group/group_cipher.js +89 -0
  13. package/lib/Signal/Group/index.js +136 -0
  14. package/lib/Signal/Group/keyhelper.js +73 -0
  15. package/lib/Signal/Group/sender-chain-key.js +32 -0
  16. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  17. package/lib/Signal/Group/sender-key-message.js +69 -0
  18. package/lib/Signal/Group/sender-key-name.js +50 -0
  19. package/lib/Signal/Group/sender-key-record.js +44 -0
  20. package/lib/Signal/Group/sender-key-state.js +97 -0
  21. package/lib/Signal/Group/sender-message-key.js +30 -0
  22. package/lib/Signal/libsignal.js +490 -0
  23. package/lib/Signal/lid-mapping.js +262 -0
  24. package/lib/Socket/Client/index.js +30 -0
  25. package/lib/Socket/Client/types.js +13 -0
  26. package/lib/Socket/Client/websocket.js +62 -0
  27. package/lib/Socket/aigroups.js +240 -0
  28. package/lib/Socket/business.js +422 -0
  29. package/lib/Socket/chats.js +1816 -0
  30. package/lib/Socket/communities.js +549 -0
  31. package/lib/Socket/graphql.js +656 -0
  32. package/lib/Socket/groups.js +764 -0
  33. package/lib/Socket/index.js +39 -0
  34. package/lib/Socket/interactive-handler.js +522 -0
  35. package/lib/Socket/interop.js +549 -0
  36. package/lib/Socket/luxu.js +387 -0
  37. package/lib/Socket/managed-account.js +183 -0
  38. package/lib/Socket/messages-recv.js +2440 -0
  39. package/lib/Socket/messages-send.js +1853 -0
  40. package/lib/Socket/mex.js +60 -0
  41. package/lib/Socket/newsletter.js +820 -0
  42. package/lib/Socket/privacy.js +449 -0
  43. package/lib/Socket/registration.js +427 -0
  44. package/lib/Socket/socket.js +1092 -0
  45. package/lib/Socket/text-router.js +83 -0
  46. package/lib/Socket/username.js +243 -0
  47. package/lib/Store/index.js +36 -0
  48. package/lib/Store/keyed-db.js +108 -0
  49. package/lib/Store/make-cache-manager-store.js +90 -0
  50. package/lib/Store/make-in-memory-store.js +604 -0
  51. package/lib/Store/make-ordered-dictionary.js +81 -0
  52. package/lib/Store/object-repository.js +29 -0
  53. package/lib/Types/Auth.js +38 -0
  54. package/lib/Types/Bussines.js +2 -0
  55. package/lib/Types/Call.js +2 -0
  56. package/lib/Types/Chat.js +4 -0
  57. package/lib/Types/Contact.js +2 -0
  58. package/lib/Types/Events.js +2 -0
  59. package/lib/Types/GroupMetadata.js +2 -0
  60. package/lib/Types/Label.js +27 -0
  61. package/lib/Types/LabelAssociation.js +9 -0
  62. package/lib/Types/Message.js +95 -0
  63. package/lib/Types/Mex.js +112 -0
  64. package/lib/Types/Newsletter.js +121 -0
  65. package/lib/Types/Product.js +2 -0
  66. package/lib/Types/Signal.js +2 -0
  67. package/lib/Types/Socket.js +2 -0
  68. package/lib/Types/State.js +70 -0
  69. package/lib/Types/USync.js +2 -0
  70. package/lib/Types/index.js +55 -0
  71. package/lib/Utils/auth-utils.js +306 -0
  72. package/lib/Utils/browser-utils.js +114 -0
  73. package/lib/Utils/business.js +247 -0
  74. package/lib/Utils/chat-utils.js +1208 -0
  75. package/lib/Utils/command-loader.js +100 -0
  76. package/lib/Utils/companion-reg-client-utils.js +42 -0
  77. package/lib/Utils/consumer-application.js +107 -0
  78. package/lib/Utils/crypto.js +155 -0
  79. package/lib/Utils/curve25519-js.js +275 -0
  80. package/lib/Utils/decode-wa-message.js +560 -0
  81. package/lib/Utils/event-buffer.js +607 -0
  82. package/lib/Utils/generics.js +563 -0
  83. package/lib/Utils/group-history.js +60 -0
  84. package/lib/Utils/history.js +244 -0
  85. package/lib/Utils/identity-change-handler.js +52 -0
  86. package/lib/Utils/index.js +57 -0
  87. package/lib/Utils/jid-display-normalization.js +218 -0
  88. package/lib/Utils/link-preview.js +143 -0
  89. package/lib/Utils/logger.js +9 -0
  90. package/lib/Utils/lt-hash.js +39 -0
  91. package/lib/Utils/make-mutex.js +36 -0
  92. package/lib/Utils/message-composer.js +479 -0
  93. package/lib/Utils/message-retry-manager.js +270 -0
  94. package/lib/Utils/messages-media.js +896 -0
  95. package/lib/Utils/messages.js +2904 -0
  96. package/lib/Utils/meta-ai-msmsg.js +262 -0
  97. package/lib/Utils/native-bridge.js +82 -0
  98. package/lib/Utils/noise-handler.js +196 -0
  99. package/lib/Utils/offline-node-processor.js +42 -0
  100. package/lib/Utils/pre-key-manager.js +107 -0
  101. package/lib/Utils/process-message.js +1048 -0
  102. package/lib/Utils/reporting-utils.js +262 -0
  103. package/lib/Utils/session-pool.js +94 -0
  104. package/lib/Utils/signal.js +224 -0
  105. package/lib/Utils/stanza-ack.js +40 -0
  106. package/lib/Utils/sticker.js +145 -0
  107. package/lib/Utils/sync-action-utils.js +54 -0
  108. package/lib/Utils/tc-token-utils.js +161 -0
  109. package/lib/Utils/use-multi-file-auth-state.js +121 -0
  110. package/lib/Utils/validate-connection.js +219 -0
  111. package/lib/Utils/view-once-cache.js +79 -0
  112. package/lib/Utils/voip-rekey.js +22 -0
  113. package/lib/WABinary/constants.js +1304 -0
  114. package/lib/WABinary/decode.js +343 -0
  115. package/lib/WABinary/encode.js +228 -0
  116. package/lib/WABinary/generic-utils.js +240 -0
  117. package/lib/WABinary/index.js +33 -0
  118. package/lib/WABinary/jid-utils.js +361 -0
  119. package/lib/WABinary/types.js +2 -0
  120. package/lib/WAM/BinaryInfo.js +13 -0
  121. package/lib/WAM/constants.js +39486 -0
  122. package/lib/WAM/encode.js +142 -0
  123. package/lib/WAM/index.js +31 -0
  124. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +55 -0
  125. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
  126. package/lib/WAUSync/Protocols/USyncContactProtocol.js +54 -0
  127. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  128. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  129. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +59 -0
  130. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +31 -0
  131. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
  132. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
  133. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +39 -0
  134. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
  135. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +27 -0
  136. package/lib/WAUSync/Protocols/index.js +39 -0
  137. package/lib/WAUSync/USyncQuery.js +133 -0
  138. package/lib/WAUSync/USyncUser.js +50 -0
  139. package/lib/WAUSync/index.js +31 -0
  140. package/lib/antiban.js +4637 -0
  141. package/lib/index.js +45 -0
  142. package/package.json +107 -0
@@ -0,0 +1,422 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ exports.makeBusinessSocket = void 0
4
+ const Utils_1 = require('../Utils')
5
+ const business_1 = require('../Utils/business')
6
+ const WABinary_1 = require('../WABinary')
7
+ const generic_utils_1 = require('../WABinary/generic-utils')
8
+ const messages_recv_1 = require('./messages-recv')
9
+ const makeBusinessSocket = config => {
10
+ const sock = (0, messages_recv_1.makeMessagesRecvSocket)(config)
11
+ const { authState, query, waUploadToServer } = sock
12
+ const updateBussinesProfile = async args => {
13
+ const node = []
14
+ const simpleFields = ['address', 'email', 'description']
15
+ node.push(
16
+ ...simpleFields
17
+ .filter(key => args[key] !== undefined && args[key] !== null)
18
+ .map(key => ({
19
+ tag: key,
20
+ attrs: {},
21
+ content: args[key]
22
+ }))
23
+ )
24
+ if (args.websites !== undefined) {
25
+ node.push(
26
+ ...args.websites.map(website => ({
27
+ tag: 'website',
28
+ attrs: {},
29
+ content: website
30
+ }))
31
+ )
32
+ }
33
+ if (args.hours !== undefined) {
34
+ node.push({
35
+ tag: 'business_hours',
36
+ attrs: { timezone: args.hours.timezone },
37
+ content: args.hours.days.map(dayConfig => {
38
+ const base = {
39
+ tag: 'business_hours_config',
40
+ attrs: {
41
+ day_of_week: dayConfig.day,
42
+ mode: dayConfig.mode
43
+ }
44
+ }
45
+ if (dayConfig.mode === 'specific_hours') {
46
+ return {
47
+ ...base,
48
+ attrs: {
49
+ ...base.attrs,
50
+ open_time: dayConfig.openTimeInMinutes,
51
+ close_time: dayConfig.closeTimeInMinutes
52
+ }
53
+ }
54
+ }
55
+ return base
56
+ })
57
+ })
58
+ }
59
+ const result = await query({
60
+ tag: 'iq',
61
+ attrs: {
62
+ to: WABinary_1.S_WHATSAPP_NET,
63
+ type: 'set',
64
+ xmlns: 'w:biz'
65
+ },
66
+ content: [
67
+ {
68
+ tag: 'business_profile',
69
+ attrs: {
70
+ v: '3',
71
+ mutation_type: 'delta'
72
+ },
73
+ content: node
74
+ }
75
+ ]
76
+ })
77
+ return result
78
+ }
79
+ const updateCoverPhoto = async photo => {
80
+ const { fileSha256, filePath } = await (0, Utils_1.getRawMediaUploadData)(photo, 'biz-cover-photo')
81
+ const fileSha256B64 = fileSha256.toString('base64')
82
+ const { meta_hmac, fbid, ts } = await waUploadToServer(filePath, {
83
+ fileEncSha256B64: fileSha256B64,
84
+ mediaType: 'biz-cover-photo'
85
+ })
86
+ await query({
87
+ tag: 'iq',
88
+ attrs: {
89
+ to: WABinary_1.S_WHATSAPP_NET,
90
+ type: 'set',
91
+ xmlns: 'w:biz'
92
+ },
93
+ content: [
94
+ {
95
+ tag: 'business_profile',
96
+ attrs: {
97
+ v: '3',
98
+ mutation_type: 'delta'
99
+ },
100
+ content: [
101
+ {
102
+ tag: 'cover_photo',
103
+ attrs: { id: String(fbid), op: 'update', token: meta_hmac, ts: String(ts) }
104
+ }
105
+ ]
106
+ }
107
+ ]
108
+ })
109
+ return fbid
110
+ }
111
+ const removeCoverPhoto = async id => {
112
+ return await query({
113
+ tag: 'iq',
114
+ attrs: {
115
+ to: WABinary_1.S_WHATSAPP_NET,
116
+ type: 'set',
117
+ xmlns: 'w:biz'
118
+ },
119
+ content: [
120
+ {
121
+ tag: 'business_profile',
122
+ attrs: {
123
+ v: '3',
124
+ mutation_type: 'delta'
125
+ },
126
+ content: [
127
+ {
128
+ tag: 'cover_photo',
129
+ attrs: { op: 'delete', id }
130
+ }
131
+ ]
132
+ }
133
+ ]
134
+ })
135
+ }
136
+ const getCatalog = async ({ jid, limit, cursor }) => {
137
+ jid = jid || authState.creds.me?.id
138
+ jid = (0, WABinary_1.jidNormalizedUser)(jid)
139
+ const queryParamNodes = [
140
+ {
141
+ tag: 'limit',
142
+ attrs: {},
143
+ content: Buffer.from((limit || 10).toString())
144
+ },
145
+ {
146
+ tag: 'width',
147
+ attrs: {},
148
+ content: Buffer.from('100')
149
+ },
150
+ {
151
+ tag: 'height',
152
+ attrs: {},
153
+ content: Buffer.from('100')
154
+ }
155
+ ]
156
+ if (cursor) {
157
+ queryParamNodes.push({
158
+ tag: 'after',
159
+ attrs: {},
160
+ content: cursor
161
+ })
162
+ }
163
+ const result = await query({
164
+ tag: 'iq',
165
+ attrs: {
166
+ to: WABinary_1.S_WHATSAPP_NET,
167
+ type: 'get',
168
+ xmlns: 'w:biz:catalog'
169
+ },
170
+ content: [
171
+ {
172
+ tag: 'product_catalog',
173
+ attrs: {
174
+ jid,
175
+ allow_shop_source: 'true'
176
+ },
177
+ content: queryParamNodes
178
+ }
179
+ ]
180
+ })
181
+ return (0, business_1.parseCatalogNode)(result)
182
+ }
183
+ const getCollections = async (jid, limit = 51) => {
184
+ jid = jid || authState.creds.me?.id
185
+ jid = (0, WABinary_1.jidNormalizedUser)(jid)
186
+ const result = await query({
187
+ tag: 'iq',
188
+ attrs: {
189
+ to: WABinary_1.S_WHATSAPP_NET,
190
+ type: 'get',
191
+ xmlns: 'w:biz:catalog',
192
+ smax_id: '35'
193
+ },
194
+ content: [
195
+ {
196
+ tag: 'collections',
197
+ attrs: {
198
+ biz_jid: jid
199
+ },
200
+ content: [
201
+ {
202
+ tag: 'collection_limit',
203
+ attrs: {},
204
+ content: Buffer.from(limit.toString())
205
+ },
206
+ {
207
+ tag: 'item_limit',
208
+ attrs: {},
209
+ content: Buffer.from(limit.toString())
210
+ },
211
+ {
212
+ tag: 'width',
213
+ attrs: {},
214
+ content: Buffer.from('100')
215
+ },
216
+ {
217
+ tag: 'height',
218
+ attrs: {},
219
+ content: Buffer.from('100')
220
+ }
221
+ ]
222
+ }
223
+ ]
224
+ })
225
+ return (0, business_1.parseCollectionsNode)(result)
226
+ }
227
+ const getOrderDetails = async (orderId, tokenBase64) => {
228
+ const result = await query({
229
+ tag: 'iq',
230
+ attrs: {
231
+ to: WABinary_1.S_WHATSAPP_NET,
232
+ type: 'get',
233
+ xmlns: 'fb:thrift_iq',
234
+ smax_id: '5'
235
+ },
236
+ content: [
237
+ {
238
+ tag: 'order',
239
+ attrs: {
240
+ op: 'get',
241
+ id: orderId
242
+ },
243
+ content: [
244
+ {
245
+ tag: 'image_dimensions',
246
+ attrs: {},
247
+ content: [
248
+ {
249
+ tag: 'width',
250
+ attrs: {},
251
+ content: Buffer.from('100')
252
+ },
253
+ {
254
+ tag: 'height',
255
+ attrs: {},
256
+ content: Buffer.from('100')
257
+ }
258
+ ]
259
+ },
260
+ {
261
+ tag: 'token',
262
+ attrs: {},
263
+ content: Buffer.from(tokenBase64)
264
+ }
265
+ ]
266
+ }
267
+ ]
268
+ })
269
+ return (0, business_1.parseOrderDetailsNode)(result)
270
+ }
271
+ /**
272
+ * Get linked Facebook/Instagram accounts (WhatsApp-as-a-page linking).
273
+ * Ported from WhatsApp Web's WASmaxBizLinkingGetLinkedAccountsRPC.
274
+ * @returns {Promise<{ pageInfo: object, linkState?: string, node: object } | undefined>}
275
+ */
276
+ const getLinkedAccounts = async () => {
277
+ const result = await query({
278
+ tag: 'iq',
279
+ attrs: { to: WABinary_1.S_WHATSAPP_NET, type: 'get', xmlns: 'fb:thrift_iq', smax_id: '42' },
280
+ content: [{ tag: 'linked_accounts', attrs: {} }]
281
+ })
282
+ const fbPage = (0, WABinary_1.getBinaryNodeChild)(result, 'fb_page')
283
+ if (!fbPage) return undefined
284
+ const button = (0, WABinary_1.getBinaryNodeChild)(fbPage, 'whatsapp_as_page_button')
285
+ return { pageInfo: fbPage.attrs, linkState: button?.attrs?.state, node: fbPage }
286
+ }
287
+ /**
288
+ * Get business eligibility for the given features (meta_verified / marketing_messages / genai).
289
+ * Ported from WhatsApp Web's WASmaxBizMarketingMessageGetBusinessEligibilityRPC.
290
+ * @param {{ metaVerified?: any, marketingMessages?: any, genai?: any }} [features]
291
+ */
292
+ const getBusinessEligibility = async (features = {}) => {
293
+ const attrs = {}
294
+ if (features.metaVerified !== undefined) attrs.meta_verified = String(features.metaVerified)
295
+ if (features.marketingMessages !== undefined) attrs.marketing_messages = String(features.marketingMessages)
296
+ if (features.genai !== undefined) attrs.genai = String(features.genai)
297
+ const result = await query({
298
+ tag: 'iq',
299
+ attrs: { to: WABinary_1.S_WHATSAPP_NET, type: 'get', xmlns: 'w:biz', smax_id: '139' },
300
+ content: [{ tag: 'features', attrs }]
301
+ })
302
+ const mv = (0, WABinary_1.getBinaryNodeChild)(result, 'meta_verified')
303
+ return mv ? { status: mv.attrs?.status, ...mv.attrs } : undefined
304
+ }
305
+ const productUpdate = async (productId, update) => {
306
+ update = await (0, business_1.uploadingNecessaryImagesOfProduct)(update, waUploadToServer)
307
+ const editNode = (0, business_1.toProductNode)(productId, update)
308
+ const result = await query({
309
+ tag: 'iq',
310
+ attrs: {
311
+ to: WABinary_1.S_WHATSAPP_NET,
312
+ type: 'set',
313
+ xmlns: 'w:biz:catalog'
314
+ },
315
+ content: [
316
+ {
317
+ tag: 'product_catalog_edit',
318
+ attrs: { v: '1' },
319
+ content: [
320
+ editNode,
321
+ {
322
+ tag: 'width',
323
+ attrs: {},
324
+ content: '100'
325
+ },
326
+ {
327
+ tag: 'height',
328
+ attrs: {},
329
+ content: '100'
330
+ }
331
+ ]
332
+ }
333
+ ]
334
+ })
335
+ const productCatalogEditNode = (0, generic_utils_1.getBinaryNodeChild)(result, 'product_catalog_edit')
336
+ const productNode = (0, generic_utils_1.getBinaryNodeChild)(productCatalogEditNode, 'product')
337
+ return (0, business_1.parseProductNode)(productNode)
338
+ }
339
+ const productCreate = async create => {
340
+ // ensure isHidden is defined
341
+ create.isHidden = !!create.isHidden
342
+ create = await (0, business_1.uploadingNecessaryImagesOfProduct)(create, waUploadToServer)
343
+ const createNode = (0, business_1.toProductNode)(undefined, create)
344
+ const result = await query({
345
+ tag: 'iq',
346
+ attrs: {
347
+ to: WABinary_1.S_WHATSAPP_NET,
348
+ type: 'set',
349
+ xmlns: 'w:biz:catalog'
350
+ },
351
+ content: [
352
+ {
353
+ tag: 'product_catalog_add',
354
+ attrs: { v: '1' },
355
+ content: [
356
+ createNode,
357
+ {
358
+ tag: 'width',
359
+ attrs: {},
360
+ content: '100'
361
+ },
362
+ {
363
+ tag: 'height',
364
+ attrs: {},
365
+ content: '100'
366
+ }
367
+ ]
368
+ }
369
+ ]
370
+ })
371
+ const productCatalogAddNode = (0, generic_utils_1.getBinaryNodeChild)(result, 'product_catalog_add')
372
+ const productNode = (0, generic_utils_1.getBinaryNodeChild)(productCatalogAddNode, 'product')
373
+ return (0, business_1.parseProductNode)(productNode)
374
+ }
375
+ const productDelete = async productIds => {
376
+ const result = await query({
377
+ tag: 'iq',
378
+ attrs: {
379
+ to: WABinary_1.S_WHATSAPP_NET,
380
+ type: 'set',
381
+ xmlns: 'w:biz:catalog'
382
+ },
383
+ content: [
384
+ {
385
+ tag: 'product_catalog_delete',
386
+ attrs: { v: '1' },
387
+ content: productIds.map(id => ({
388
+ tag: 'product',
389
+ attrs: {},
390
+ content: [
391
+ {
392
+ tag: 'id',
393
+ attrs: {},
394
+ content: Buffer.from(id)
395
+ }
396
+ ]
397
+ }))
398
+ }
399
+ ]
400
+ })
401
+ const productCatalogDelNode = (0, generic_utils_1.getBinaryNodeChild)(result, 'product_catalog_delete')
402
+ return {
403
+ deleted: +(productCatalogDelNode?.attrs.deleted_count || 0)
404
+ }
405
+ }
406
+ return {
407
+ ...sock,
408
+ logger: config.logger,
409
+ getOrderDetails,
410
+ getLinkedAccounts,
411
+ getBusinessEligibility,
412
+ getCatalog,
413
+ getCollections,
414
+ productCreate,
415
+ productDelete,
416
+ productUpdate,
417
+ updateBussinesProfile,
418
+ updateCoverPhoto,
419
+ removeCoverPhoto
420
+ }
421
+ }
422
+ exports.makeBusinessSocket = makeBusinessSocket